读取和写入制表符分隔文件格式
Contents
[
Hide
]
可能的使用场景
Microsoft Excel支持多种格式,如XLS、XLSX、XLSM、XLSB、CSV、制表符分隔等。Aspose.Cells也支持其中许多格式。本文解释了如何使用Aspose.Cells读取和写入具有制表符分隔格式的Excel文件。
读取和写入制表符分隔文件格式
以下示例代码加载源制表符分隔文件,并读取其单元格A1,然后将其内容复制到单元格C4并保存为输出制表符分隔文件。
示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 tab delimited file | |
U16String srcReadWriteTabDelimited = dirPath + u"srcReadWriteTabDelimited.txt"; | |
//Path of output tab delimited file | |
U16String outReadWriteTabDelimited = outPath + u"outReadWriteTabDelimited.txt"; | |
//Read source tab delimited file | |
Workbook wb(srcReadWriteTabDelimited); | |
//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 tab delimited format | |
wb.Save(outReadWriteTabDelimited, SaveFormat::TabDelimited); | |
Aspose::Cells::Cleanup(); |