タブ区切りファイル形式の読み取りと書き込み
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
//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\\"); | |
//Path of input tab delimited file | |
StringPtr srcReadWriteTabDelimited = dirPath->StringAppend(new String(L"srcReadWriteTabDelimited.txt")); | |
//Path of output tab delimited file | |
StringPtr outReadWriteTabDelimited = outPath->StringAppend(new String(L"outReadWriteTabDelimited.txt")); | |
//Read source tab delimited file | |
intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook(srcReadWriteTabDelimited); | |
//Access first worksheet | |
intrusive_ptr<IWorksheet> ws = wb->GetIWorksheets()->GetObjectByIndex(0); | |
//Access cell A1 | |
intrusive_ptr<ICell> cell = ws->GetICells()->GetObjectByIndex(new String("A1")); | |
//Get the string value of cell A1 | |
StringPtr strVal = cell->GetStringValue(); | |
//Print the string value of cell A1 | |
StringPtr cellValue = new String("Cell Value: "); | |
Console::WriteLine(cellValue->StringAppend(strVal)); | |
//Access cell C4 | |
cell = ws->GetICells()->GetObjectByIndex(new String("C4")); | |
//Put the string value of cell A1 into C4 | |
intrusive_ptr<String> strValPtr = new String(strVal); | |
cell->PutValue(strValPtr); | |
//Save the workbook in tab delimited format | |
wb->Save(outReadWriteTabDelimited, SaveFormat_TabDelimited); |