PDA

View Full Version : Can't save excel file with QaxObject



Mirmilstein
28th March 2012, 16:00
So guys here is my code. I sit here for hours and cannot find any solution :(

QAxWidget excel("Excel.Application");
excel.setProperty("Visible", false );
QAxObject * workbooks = excel.querySubObject("WorkBooks");
QAxObject *workbook = workbooks->querySubObject( "Open(const QString&)", FileName.c_str() );
QAxObject * worksheet = workbook->querySubObject("Worksheets(int)", 1);
worksheet->setProperty("Name", "Anlagenart1");
//here I write into the file
//now I want to save
QVariant newFileName(ResultName.c_str());
excel.setProperty("Visible", true );
workbooks->querySubObject("SaveAs (const QString&)", ResultName.c_str());
workbook->dynamicCall("SaveAs (const QString&)", ResultName.c_str());
workbook->querySubObject("SaveAs (const QString&)", ResultName.c_str());
excel.dynamicCall("SaveAs (const QVariant&)",newFileName );
workbook->querySubObject("SaveAs (const QString&)", QString("c:\test\docbyqt.xls"));


You can see that I tried almost every combination with no success....Please help me and save my day ^^

EDIT:
When I try to save it as "test.xls" ist works and the file goes to "my documents"...any other folder do not work :(

jh
31st March 2012, 14:56
try '/' instead of '\'
hope that helps.
regards, jh

d_stranz
31st March 2012, 19:36
workbook->querySubObject("SaveAs (const QString&)", QString("c:\test\docbyqt.xls"));

To further expand on this: the "\t" combination is being interpreted as a "tab" escape sequence. If you want to use backslashes (\) instead of forward slashes (/) to delimit file names, then you have to escape each one by doubling it: "c:\\test\\docbyqt.xls" This is standard C/C++, but it is a frequent mistake.

I have no idea if the querySubObject() call is correct. I would be surprised if QString is acceptable as a parameter in a COM call, but maybe QAxObject does some magic to turn it into a BSTR.

And please use [CODE] tags when you post source code.

Mirmilstein
2nd April 2012, 10:05
thanks for the help, works fine now with \\!

the next time i will use code ;)