This project has moved. For the latest updates, please go here.

Updating an exiting excel sheet using epplus giving error

Mar 24, 2014 at 12:23 PM
Edited Mar 25, 2014 at 6:20 AM

I want to update existing '.xlsx' file using Epplus. I have Open Office installed at my system. I want to open 'Sample.xlsx' file which is also creating by Epplus for fisrt time and if file already exists then update it. I am using below code for updating file but getting error 'General Input/Output error' when trying to open file using 'Process.start("...")

Using below code :
ExcelPackage l_ExcelPackg = null;
 ExcelWorksheet l_ExcelSheet = null;

//Update existing file 
FileInfo l_FileInfo = new FileInfo(@"C:\\Files\\Sample.xlsx");
 l_ExcelPackg = new ExcelPackage(l_FileInfo);
ExcelWorkbook l_WorkBook = l_ExcelPackg.Workbook;

//Get 10th sheet of excel to update
//1 to 9 sheets keep unchanged

l_ExcelSheet = l_WorkBook.Worksheets[10];

//First row having column names
foreach (DataColumn l_dcColumn in p_dtSelectedRows.Columns)
    l_ExcelSheet.Cells[1, l_intColums].Value = 
     l_ExcelSheet.Cells[1, l_intColums].Style.Font.Bold = true;

byte[] l_byteArr = l_ExcelPackg.GetAsByteArray();
File.WriteAllBytes(p_strFilePath, l_byteArr); 

ProcessStartInfo l_objProcess = new ProcessStartInfo(@"C:\\Files\\Sample.xlsx");

Mar 25, 2014 at 10:29 PM
Edited Mar 25, 2014 at 10:49 PM

I can't seem to reproduce the error.

Could it be that you have the Sample.xlsx open in excel while you are running your code?