Results 1 to 4 of 4

Thread: Can't save excel file with QaxObject

  1. #1

    Default Can't save excel file with QaxObject

    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
    Last edited by Mirmilstein; 28th March 2012 at 16:39.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can't save excel file with QaxObject

    try '/' instead of '\'
    hope that helps.
    regards, jh

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can't save excel file with QaxObject

    Qt Code:
    1. workbook->querySubObject("SaveAs (const QString&)", QString("c:\test\docbyqt.xls"));
    To copy to clipboard, switch view to plain text mode 
    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.

  4. #4

    Default Re: Can't save excel file with QaxObject

    thanks for the help, works fine now with \\!

    the next time i will use code

Similar Threads

  1. How can I Read Write Excel File
    By xingshaoyong in forum Qt Programming
    Replies: 6
    Last Post: 13th July 2011, 21:16
  2. problem to read excel file
    By keyurparekh in forum Qt Programming
    Replies: 4
    Last Post: 27th June 2011, 14:25
  3. Formatting Excel File
    By bismitapadhy in forum Qt Programming
    Replies: 2
    Last Post: 27th May 2009, 12:16
  4. How to read Excel file with Qt
    By HelloDan in forum Qt Programming
    Replies: 3
    Last Post: 13th May 2009, 21:27
  5. Read \Write Excel File using Qt
    By xingshaoyong in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 23:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.