保存文件

保存文件的不同方法

Aspose.Cells 提供了工作簿它表示一个 Microsoft Excel 文件并提供处理 Excel 文件所需的方法。这工作簿类提供了救球用于保存 Excel 文件的方法。这救球方法有许多用于以不同方式保存文件的重载。文件保存的文件格式由保存格式枚举。

将文件保存到某个位置

要将文件保存到存储位置,请指定文件名(包括存储路径)和所需的文件格式(来自保存格式枚举)调用时工作簿对象的救球方法。

//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Source directory path
StringPtr dirPath = new String("..\\Data\\LoadingSavingAndConverting\\");
//Output directory path
StringPtr outPath = new String("..\\Data\\Output\\");
//Load sample Excel file
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(dirPath->StringAppend(new String("sampleExcelFile.xlsx")));
//Save in Excel 97-2003 format
workbook->Save(outPath->StringAppend(new String("outputSavingFiletoSomeLocationExcel97-2003.xls")));
//OR
workbook->Save(outPath->StringAppend(new String("outputSavingFiletoSomeLocationOrExcel97-2003.xls")), SaveFormat_Excel97To2003);
//Save in Excel2007 xlsx format
workbook->Save(outPath->StringAppend(new String("outputSavingFiletoSomeLocationXlsx.xlsx")), SaveFormat_Xlsx);

将文件保存到流

要将文件保存到流中,请创建一个 MemoryStream 或 FileStream 对象,然后通过调用工作簿对象的救球方法。使用指定所需的文件格式保存格式调用时的枚举救球方法。

//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Source directory path
StringPtr dirPath = new String("..\\Data\\LoadingSavingAndConverting\\");
//Output directory path
StringPtr outPath = new String("..\\Data\\Output\\");
//Load sample Excel file
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(dirPath->StringAppend(new String("sampleExcelFile.xlsx")));
//Create FileStream object
intrusive_ptr<FileStream> stream = new FileStream(outPath->StringAppend(new String("outputSavingFiletoStream.xlsx")), FileMode_CreateNew);
//Save the Workbook to Stream
workbook->Save(stream, SaveFormat_Xlsx);
stream->Close();