I'm creating an Excel chart using C++. Im having problem with saving workbook with few sheets. Here is my code:
try
{
CoInitialize(NULL);
Excel::_ApplicationPtr XL;
XL.CreateInstance(L"Excel.Application");
XL->Visible=false;
Excel::_WorkbookPtr workbook = XL->Workbooks->Add(Excel::xlWorksheet);
Excel::_WorksheetPtr pSheet= XL->ActiveSheet;
for (i='1';i<='z';i++){
pSheet = XL->Worksheets->Add();
char arr[25];
sprintf(arr, "Podaci za %c", i);
pSheet->Name = arr;
...
}
pSheet = XL->Worksheets->Add();
pSheet->Name = "some page";
pSheet->SaveAs("c:\\test.xls");
workbook->Close();
XL->Quit();
}
catch(_com_error & error)
{
printf("\n Greska u komunikaciji s MS Excelom.");
}
CoUninitialize();
I have a for loop that creates few sheets. "..." represents the part of code where i fill tables. It all worked great until i tried saving it. Now when it cones to SaveAs() jumps to catch. I also tried using workbook->saveas("table.xls"); but I dont know the right syntax.
Thanks for help in advance!