0

I'm using EPPlus to write data to Excel, which works great. I'm writing a header row from column A to column AI and am using the code below to write the data

(subset of the code)

using (ExcelPackage pck = new ExcelPackage())
{
    ExcelWorksheet ws = pck.Workbook.Worksheets.Add(customer);
    ws.Cells["A1"].Value = "First Name";
    ws.Cells["B1"].Value = "Last Name";
    ws.Cells["C1"].Value = "Address1";
    ws.Cells["D1"].Value = "Address2";
    ws.Cells["E1"].Value = "City";
    ws.Cells["F1"].Value = "State";
    ws.Cells["G1"].Value = "Zip";
    ws.Cells["H1"].Value = "Phone";
    
    //keep writing data to I, J, K, L, etc
    
    ws.Cells["AF1"].Value = "Hire Date";
    ws.Cells["AG1"].Value = "Manager Name";
    ws.Cells["AH1"].Value = "Manager Hire Date";
    ws.Cells["AI1"].Value = "Simlcam Number";

    FileInfo fi = new FileInfo("C:\\Test\\EPPlusWorkbook.xlsx");
    await pck.SaveAsAsync(fi);
}

Now this code writes headers perfectly, UNTIL it reaches cell AF1 then for whatever reason the no further header info is written to the workbook.

Stepping thro the code shows that the lines of code are hit so there is no error displayed.

  • And if you save the xlsx and rename it to .zip and open it and open the xml file inside, you see the data or not? – Caius Jard Jan 29 '21 at 22:52
  • Which .xml file do I need to open in the .zip there are multiple... – James Mandatory Jan 29 '21 at 22:55
  • Instead of hardcoding so much, why don't you use a file as a template with the headers already in place? – Camilo Terevinto Jan 29 '21 at 22:58
  • @CamiloTerevinto - if possible, I'd rather hardcode the headers in, if I must use a template workbook (i'll have 3 - 4 different templates) I can go that route. – James Mandatory Jan 29 '21 at 22:59
  • Can't remember- look in all of them (use a text editor that does find-in-files and look for the value out of A1..) – Caius Jard Jan 29 '21 at 23:06
  • @CaiusJard - opening the xml file same result, the last header written to excel is ``AE1`` – James Mandatory Jan 29 '21 at 23:10
  • At least we know excel isn't the problem! So.. Does it also happen with a different version of epplus? What if you change the values written? If you use the source code rather than the package can you trace the problem? https://github.com/JanKallman/EPPlus – Caius Jard Jan 29 '21 at 23:14
  • @CaiusJard - I have only used this version of EPPlus. How would I use the source code rather then the package? Copy/paste it into a class in my project? – James Mandatory Jan 29 '21 at 23:15
  • I normally just hit the download zip option in GitHub, extract it, add its csproj to my solution then add a reference and choose "project" type reference, ticking the added project – Caius Jard Jan 29 '21 at 23:17
  • @CaiusJard - when I extract the .zip from github there is no csproj file? – James Mandatory Jan 29 '21 at 23:25
  • I used the posted code and EPPlus version 4.0, and I was unable to reproduce what you describe. The only change I made in the code was changing the line… `await pck.SaveAsAsync(fi);` … to … `pck.SaveAs(fi);`, however, all the column headers showed as expected. Is there something else going on after this? – JohnG Jan 30 '21 at 00:26
  • @JohnG - no that is the end of the code. I wonder if it's an issue with my version, I'm using ``5.5.2`` let me see if I can figure out how to downgrade to 4.0 and test there. I change the ``SaveAs`` line to test and still headers are not written. It's interesting to me that the Header row won't write, but the data going into the rows will. – James Mandatory Jan 30 '21 at 00:34
  • If the data writes... i don't see how the version would matter. – JohnG Jan 30 '21 at 00:37
  • @JohnG - I downgraded EPPlus to ``4.0.5`` and no issue. Seems to be an issue specific to ``5.5.2`` – James Mandatory Jan 30 '21 at 00:41
  • Hmm that is strange, but if works for you, then I am glad you got it working. – JohnG Jan 30 '21 at 00:44

0 Answers0