如何使用ASPOSE.Cells实例化Office 365 Excel文件?

时间:2019-05-07 13:12:06

标签: c# excel aspose-cells

当我尝试创建从Office 365环境生成的Excel文件(.xlsb格式)的实例时,会引发错误。

 string fileName = "Subhajit_test.xlsb";
 Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(fileName);

上面的代码抛出以下错误:

Invalid workbook setting in the xlsb workbook.
   at .?.??()
   at .?.Read( , ?? )
   at ..Read()
   at ..Read(Workbook , LoadOptions )
   at Aspose.Cells.Workbook.?(Stream , LoadOptions , Boolean )
   at Aspose.Cells.Workbook.?(String , LoadOptions )
   at Aspose.Cells.Workbook..ctor(String file)
   at ASPOSE.GetDataFromExcel..ctor(String fileName)
```[enter image description here][1]


  [1]: https://i.stack.imgur.com/uBBrK.png

2 个答案:

答案 0 :(得分:0)

//Instantiate a workbook.
Workbook workbook = new Workbook();
//Get the first (default) worksheet.
Worksheet sheet = workbook.Worksheets[0];
//Get the cells in the sheet.
Cells cells = sheet.Cells;
//Merging two cells (B5:C5)into a single cell(B5).
cells.Merge(4,1,1,2);
//Put some value into the merged cell.
cells["B5"].PutValue("Hello World!");
//Align the text as Center aligned.
cells["B5"].Style.HorizontalAlignment = TextAlignmentType.Center;
//Save the file.
workbook.Save("d:\\test\\test_book.xls");

有关更多参考,请检查您需要的其他Wiki主题: http://www.aspose.com/Wiki/Default.aspx/Aspose.Cells/

答案 1 :(得分:0)

我试图通过创建.xlsb文件的实例来重现该问题,并且在最新的Aspose.Cells 19.5版本上似乎可以正常工作。
在v19.2中,有关保存和打开.xlsb文件的几个问题已修复,因此,我建议您升级并尝试最新版本。

如果仍然有任何问题,请向我提供一个可运行的示例代码和模板.xlsb文件,我将检查您的问题并尝试提供帮助。
您也可以在https://forum.aspose.com/上发布问题。

注意:我是Aspose的开发人员布道者。

相关问题