0

I am required to write some data into an macro enabled workbook which was developed in 1998, i am using NPOI dotnet core library for this task. I am able to write the values into the excel correctly, however i am seeing that alignment and formatting of the sheets is lost. Screenshots below:

First one shows the file after open the file using NPOI and downloading the same, and second shows the file when it is locally opened.

after download

when the file is opened locally

below is the code i am using

public XSSFWorkbook OpenExcelFile(string filePath, string tempSavePath)
        {
            using (var stream = new FileStream(tempSavePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                var temphssfwb = new XSSFWorkbook(OPCPackage.Open(filePath));
                temphssfwb.Write(stream);
            }
            XSSFWorkbook hssfwb;
            hssfwb = new XSSFWorkbook(OPCPackage.Open(tempSavePath));
            hssfwb.CreateSheet("casevalidationsheet");
            return hssfwb;
        }

Can someone please help me understand why NPOI is ruining the alignment of my excel workbook?

aditya
  • 343
  • 2
  • 14
  • Unless this is a known issue someone can remember, I doubt anyone can just tell you why. (Maybe the formatting in the original was done with since-deprecated attributes or property names that NPOI doesn't support and just drops?) I think you'll have to unpack the before and after versions and compare the XML to see what's changed, then either dig into NPOI to find out why or ask a more specific question, probably directly to NPOI not here. – Rup Mar 06 '20 at 10:28
  • Can you open the original and re-save it with modern Excel, then try again? Or maybe save as xls, reopen and save as xlsx/m again to force it to regenerate the XML? – Rup Mar 06 '20 at 10:29
  • npoi does nothing automatically, you have to copy cellstyles and columwidth/height fonts and that stuff manually – Bacon Dec 10 '20 at 22:46

0 Answers0