简体   繁体   中英

C#: Make Excel file visible while editing (EpPlus)

I'm trying to open an Excel file to view the changes as it is taking place (via epplus). But I can't find the correct Open/Visible method.

FileInfo newFile = new FileInfo("C:\\Users\\James\\Desktop\\Book.xls");
ExcelPackage pck = new ExcelPackage(newFile);

//Make Excel sheet visible
????

//Add the Content sheet
var ws = pck.Workbook.Worksheets.Add("Content");
ws.Column(4).OutlineLevel = 1;
....
var application = new Microsoft.Office.Interop.Excel.Application();

            Workbook data = application.Workbooks.Open(inFilePath,Type.Missing,true);

I think this two lines of code should solve your propose.

You cannot do that with epplus. What is happening is EPPlus is generating raw XML files (the basis of all Office 2007 formatted files) based on what you give it and then placing them in a structured ZIP and saving it with an XLSX extension (try renaming any XLSX file to .zip and you will see it open in Explorer, 7-zip, WinRAR, etc.)

When excel actually opens it and interprets the XML it adds too it so when you hit save the XLSX will actually look different even if you didnt change anything - the difference is the calculations excel made and stored.

So there really is no way to practically view it as it is being build. That is why Epplus is targeted as a "server" API - no GUI (ie Excel) needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM