简体   繁体   English

C#:在编辑时使Excel文件可见(EpPlus)

[英]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). 我正在尝试打开一个Excel文件以查看更改的过程(通过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. 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.) 发生了什么事,EPPlus正在根据您提供的内容生成原始XML文件(所有Office 2007格式文件的基础),然后将其放在结构化的ZIP中并用XLSX扩展名保存(尝试将任何XLSX文件重命名为.zip)。并且您会看到它在资源管理器,7-zip,WinRAR等中打开)

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. 当excel实际打开它并解释XML时,它也会添加它,因此当您单击保存时,即使您没有进行任何更改,XLSX的外观实际上也会有所不同-区别是excel进行了计算并存储了。

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. 这就是为什么将Epplus定位为“服务器” API的原因-无需GUI(即Excel)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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