조직에서 회사 소프트웨어를 통해 학생 데이터, 환자 기록 및 창고 항목 목록 등과 같은 Excel 파일에 저장된 데이터를 업데이트하는 것이 일반적입니다. Aspose.Total for C++ API는 소프트웨어를 사용하여 스프레드시트를 수정하는 기능을 제공합니다. 프로그래머는 몇 줄의 API 코드를 작성하여 수정 기능으로 소프트웨어를 향상시킬 수 있습니다. Aspose.Total for C++ 패키지의 일부인 Aspose.Cells for C++ API는 이 수정 프로세스를 쉽게 만듭니다. 다음은 Excel 문서를 업데이트하는 과정입니다.
C++를 사용하여 Excel 문서 업데이트
Aspose.Cells for C++ API를 사용하여 CreateIWorkbook 을 사용하여 소스 문서를 로드합니다. GetIWorksheets()->GetObjectByIndex(0)를 사용하여 Worksheet 에 액세스하고 GetICells()->GetObjectByIndex를 사용하여 필수 셀에 액세스하십시오. PutValue 메서드를 사용하여 액세스된 셀의 콘텐츠를 수정합니다. 마지막으로 save() 메서드를 호출하여 문서를 저장합니다.
C++ 코드 - Excel 문서 업데이트
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); |