在 Office 2003 中打开 .xlsx

发布于 2024-07-30 11:50:39 字数 1141 浏览 6 评论 0原文

我使用 openxml 创建了一个 .xlsx。 我无法在 Office 2003 中打开此文件。我也尝试过使用兼容包,但该文件仍然无法打开。 如果我需要生成也可以在 Office 2003 中打开的 .xlsx,该怎么办?

我用来生成 .xlsx 的代码是:

public static void HelloWorldXlsx(string docName)
{
    SpreadsheetDocument package = SpreadsheetDocument.Create(docName, SpreadsheetDocumentType.Workbook);
    package.AddWorkbookPart();
    package.WorkbookPart.Workbook = new Workbook();
    WorksheetPart wspart = package.WorkbookPart.AddNewPart<WorksheetPart>();

    Cell cell = new Cell();
    cell.DataType = CellValues.InlineString;
    cell.InlineString = new InlineString(new DocumentFormat.OpenXml.Spreadsheet.Text("Hello World!")); 

    wspart.Worksheet = new Worksheet(new SheetData(new Row(cell)));

    wspart.Worksheet.Save();
    package.WorkbookPart.Workbook.AppendChild(new Sheets());
    Sheet sheet = new Sheet();

    sheet.Id = package.WorkbookPart.GetIdOfPart(wspart);
    sheet.SheetId = 1;
    sheet.Name = "Hello !";
    package.WorkbookPart.Workbook.GetFirstChild<Sheets>().AppendChild<Sheet>(sheet);
    package.WorkbookPart.Workbook.Save();
    package.Close();
}

I have created a .xlsx using openxml.
I am not able to open this file in office 2003.. I have also tried using compatibility pack but still the file does not open. What can be done if i need to generate .xlsx that can be opened in office 2003 as well.

Code i am using to generate .xlsx is :

public static void HelloWorldXlsx(string docName)
{
    SpreadsheetDocument package = SpreadsheetDocument.Create(docName, SpreadsheetDocumentType.Workbook);
    package.AddWorkbookPart();
    package.WorkbookPart.Workbook = new Workbook();
    WorksheetPart wspart = package.WorkbookPart.AddNewPart<WorksheetPart>();

    Cell cell = new Cell();
    cell.DataType = CellValues.InlineString;
    cell.InlineString = new InlineString(new DocumentFormat.OpenXml.Spreadsheet.Text("Hello World!")); 

    wspart.Worksheet = new Worksheet(new SheetData(new Row(cell)));

    wspart.Worksheet.Save();
    package.WorkbookPart.Workbook.AppendChild(new Sheets());
    Sheet sheet = new Sheet();

    sheet.Id = package.WorkbookPart.GetIdOfPart(wspart);
    sheet.SheetId = 1;
    sheet.Name = "Hello !";
    package.WorkbookPart.Workbook.GetFirstChild<Sheets>().AppendChild<Sheet>(sheet);
    package.WorkbookPart.Workbook.Save();
    package.Close();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房敞 2024-08-06 11:50:39

感谢您的建议。 我得到了问题的答案..我没有在代码中设置 Cell 的 cellReference 属性。

Thanks for suggestion. I got the answer to my question .. I had not set cellReference property of Cell in my code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文