gpt4 book ai didi

c# - 如何在不使用互操作的情况下通过 C# 取消隐藏 Excel 工作表

转载 作者:行者123 更新时间:2023-11-30 17:03:35 24 4
gpt4 key购买 nike

我的服务器人员还没有准备好安装 office

我在表单中编写了以下代码。它在我的机器上运行良好,但是当我上传到网上时;这是行不通的。这需要 interop dll 但服务器人员尚未准备好在服务器上安装 office。任何人都可以帮助我,因为我需要从 excel 中取消隐藏工作表

使用excel;

        Excel.Application excelApp = new Excel.Application();

string myPath = @fileLocation;
excelApp.Workbooks.Open(myPath, Missing.Value, Missing.Value,Missing.Value, Missing.Value,Missing.Value, Missing.Value,Missing.Value, Missing.Value,Missing.Value, Missing.Value,Missing.Value, Missing.Value);//,Missing.Value, Missing.Value);

//Get the first sheet.
Excel.Worksheet objSheet = (Excel.Worksheet)excelApp.ActiveWorkbook.Sheets["abc"];

//Unhide the worksheet.
objSheet.Visible = Excel.XlSheetVisibility.xlSheetVisible;
//Save As the Excel file.
excelApp.ActiveWorkbook.Save();

最佳答案

使用 Open XML SDK 并将 SheetState 属性设置为 SheetStateValues.Hidden

Sheet.State 属性

http://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.sheet.state.aspx

用于 Microsoft Office 的 Open XML SDK 2.5

http://www.microsoft.com/en-us/download/details.aspx?id=30425

不要在服务器上使用办公自动化。

enter image description here

关于c# - 如何在不使用互操作的情况下通过 C# 取消隐藏 Excel 工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18440744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com