C++ アプリケーション内で XLTM ファイルを更新しようとしているプログラマー向け, Aspose.Total for C++ API は、更新プロセスの自動化に役立ちます。 これは、Microsoft Excel ドキュメントを含む複数の形式を扱うさまざまな C++ ライブラリの完全なパッケージです。 Aspose.Total for C++ パッケージの一部である Aspose.Cells for C++ API は、この変更プロセスを容易にします。 XLTM ドキュメントを更新するプロセスは、最初にシートにアクセスし、次に C++ を使用して Excel でセル値を更新するだけで簡単です。
C++ で XLTM ファイルを更新する方法
- CreateIWorkbook を使用して XLTM ファイルをロードする
- GetIWorksheets()->GetObjectByIndex(0) を使用した関連 Worksheet および GetICells()->GetObjectByIndex を使用した関連セルへのアクセス
- PutValue メソッドを使用して、アクセスしたセルに新しいデータを挿入します
- パラメータとしてパスを指定してファイルを渡し、Save メソッドを使用してファイルを .xltm ファイルとして保存します。
変更要件
コード - C++ での XLTM ファイルの更新
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
StringPtr dirPath = new String("..\\Data\\sourcePath\\"); | |
StringPtr outPath = new String("..\\Data\\OutputPath\\"); | |
StringPtr srcCSV = dirPath->StringAppend(new String(L"srcFile.csv")); | |
StringPtr updatedCSV = outPath->StringAppend(new String(L"outReadWriteCSV.csv")); | |
intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook(srcCSV); | |
intrusive_ptr<IWorksheet> ws = wb->GetIWorksheets()->GetObjectByIndex(0); | |
intrusive_ptr<ICell> cell = ws->GetICells()->GetObjectByIndex(new String("A1")); | |
StringPtr strVal = cell->GetStringValue(); | |
StringPtr cellValue = new String("Cell Value: "); | |
Console::WriteLine(cellValue->StringAppend(strVal)); | |
cell = ws->GetICells()->GetObjectByIndex(new String("C4")); | |
intrusive_ptr<String> strValPtr = new String(strVal); | |
cell->PutValue(strValPtr); | |
wb->Save(updatedCSV, SaveFormat_CSV); |