Read and Write XLSB File Format
Possible Usage Scenarios
Microsoft Excel supports many formats like XLS, XLSX, XLSM, XLSB, CSV, etc. Aspose.Cells also supports many of these formats. This article explains how to read and write the excel file having XLSB format using Aspose.Cells.
Read and Write XLSB File Format
The following sample code loads the source XLSB file and reads its cell A1 and then copies its contents to cell C4 and saves it as output XLSB file.
Sample Code
Aspose::Cells::Startup(); | |
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Source directory path | |
U16String dirPath(u"..\\Data\\LoadingSavingAndConverting\\"); | |
//Output directory path | |
U16String outPath(u"..\\Data\\Output\\"); | |
//Path of input excel file | |
U16String srcReadWriteXLSB = dirPath + u"srcReadWriteXLSB.xlsb"; | |
//Path of output excel file | |
U16String outReadWriteXLSB = outPath + u"outReadWriteXLSB.xlsb"; | |
//Read source xlsb file | |
Workbook wb(srcReadWriteXLSB); | |
//Access first worksheet | |
Worksheet ws = wb.GetWorksheets().Get(0); | |
//Access cell A1 | |
Cell cell = ws.GetCells().Get(u"A1"); | |
//Get the string value of cell A1 | |
U16String strVal = cell.GetStringValue(); | |
//Print the string value of cell A1 | |
U16String cellValue(u"Cell Value: "); | |
std::cout << cellValue.ToUtf8() << strVal.ToUtf8() << std::endl; | |
//Access cell C4 | |
cell = ws.GetCells().Get(u"C4"); | |
//Put the string value of cell A1 into C4 | |
U16String strValPtr(strVal); | |
cell.PutValue(strValPtr); | |
//Save the workbook in XLSB format | |
wb.Save(outReadWriteXLSB, SaveFormat::Xlsb); | |
Aspose::Cells::Cleanup(); |