Excel处理开发工具Aspose.Cells功能演示:使用 C# 将 Excel 文件导出到流

为了将 Excel XLSX/XLS 文件导出或保存到内存流,我们将使用

将 Excel 文件导出到流的 C# API

为了将 Excel 文件导出到流,我们将使用Aspose.Cells for .NET。它是一个功能丰富的 API,可让您创建和操作 Excel 文件。

将 Excel 文件导出到 C# 中的 Stream

以下是使用 C# 将 Excel 文件导出到流的步骤。

  • 使用Workbook类加载 Excel 文件。
  • 创建一个新的FileStream对象。
  • 使用Workbook.Save(FileStream, SaveFormat)方法将 Excel 文件导出到流。

以下代码示例展示了如何将 Excel XLSX 文件导出到 FileStream 对象。

// Load your source workbookWorkbook workbook = new Workbook("excel.xlsx");// Create a file stream for Excel fileFileStream stream = new FileStream("output.xlsx", FileMode.CreateNew);// Export Excel file to streamworkbook.Save(stream, new XlsSaveOptions(SaveFormat.Xlsx));// Perform operations on stream// Close the streamstream.Close();

从流加载 Excel 文件

Aspose.Cells for .NET 还允许您从流中加载 Excel 文件。以下是实现此目的的步骤。

  • 创建一个新的FileStream对象并将 Excel 文件加载到其中。
  • 创建一个新的Workbook对象并使用FileStream对象对其进行初始化。
  • 使用Workbook对象对 Excel 文件执行所需的操作。

以下代码示例显示了如何从 FileStream 加载 Excel 文件。

// Create a Stream objectFileStream fstream = new FileStream("Book2.xls", FileMode.Open);// Create a Workbook object and open Excel file from streamWorkbook workbook = new Workbook(fstream);// Manipulate Excel fileConsole.WriteLine("Workbook opened using stream successfully!");// Close streamfstream.Close();

还想要更多吗可以点击阅读【Aspose最新资源在线文库】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年9月25日
下一篇 2021年9月26日

相关推荐

发表回复

登录后才能评论