Open File to Add Data

Dec 15, 2011 at 3:14 PM

I have created an excel file and added a header. The next step I have to do is add data. The system I am working with will continually be spitting out data in another thread. I need to be able to grab the data and log it into my data table. I can get the data fine, prior to this I was using a csv file. My issue is I do not know how to access my already created excel file and add the data.

Is there an open/load function I need to use to access my file? 

Dec 15, 2011 at 5:09 PM

I am currently using this code in my function and it seems to read in the correct file. p shows the correct file path, and ws shows my worksheet named "data", but setting cell [2,2] does not do anything.

	    ExcelPackage p = new ExcelPackage(new FileInfo(data_file));
            ExcelWorksheet ws = p.Workbook.Worksheets[1];

            ws.Cells[2, 2].Value = "Worked";
Dec 15, 2011 at 5:20 PM

Figured it out, I needed to save the file after.


            Byte[] bin = p.GetAsByteArray();
            File.WriteAllBytes(data_file, bin);