【问题标题】:How to unhide an excel sheet through c# without using interop如何在不使用互操作的情况下通过 C# 取消隐藏 Excel 工作表
【发布时间】:2013-08-26 22:18:02
【问题描述】:

我的服务员还没准备好安装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();

【问题讨论】:

  • 那么,您希望我们告诉您如何运行依赖于安装的 Excel 不安装 Excel 的代码?
  • 这是 ASP.NET 吗?如果是这样,那么您的服务员是对的。不要在服务器上运行 Office。
  • @HenkHolterman 这是 C# 中的 ASP.NET。如何在没有互操作的情况下工作。
  • @FrédéricHamidi 是的,先生。
  • 出现了一点谷歌搜索this post。有多个库可用。

标签: c# asp.net excel


【解决方案1】:

使用 Open XML SDK 并将Sheet 的State 属性设置为SheetStateValues.Hidden。

Sheet.State 属性

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

Open XML SDK 2.5 for Microsoft Office

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

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

【讨论】:

    猜你喜欢
    • 2016-05-27
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 2017-03-28
    • 1970-01-01
    • 2014-08-07
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多