Results 1 to 7 of 7

Thread: How to read .doc file and replace string in that file using Qt in Linux?

  1. #1
    Join Date
    Aug 2015
    Posts
    6
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default How to read .doc file and replace string in that file using Qt in Linux?

    Hi Guys,

    Is there any way to read a .doc file and replace string in that file using Qt in Linux?
    Here is my code, I have tried:

    {
    QFile file("/home/.../Desktop/file.doc");
    file.open(QFile::ReadOnly);
    QTextStream in(&file);
    QString data = in.readAll();
    file.close();

    QTextDocument *doc=new QTextDocument(data);
    int j=data.indexOf("Current",0);
    data.remove(j,7);
    data.insert(j,"Present");

    QTextDocumentWriter *writer=new QTextDocumentWriter("/home/.../Desktop/newfile.doc");
    writer->setFormat(".doc");
    writer->write(doc);
    }

    Please help me to solve this problem.

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to read .doc file and replace string in that file using Qt in Linux?

    If by "doc" you mean a Microsoft Word file, then you can't just treat is as simple plain text.

    You need to look for a library that has import and export capability for that format.

    Cheers,
    _

  3. #3
    Join Date
    Aug 2015
    Posts
    6
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to read .doc file and replace string in that file using Qt in Linux?

    Thanks for reply,

    I know about the module "ActiveQt" which will allow me to read .doc file via qactivexcontroller.
    But,I don't know, how to add this module in qt5.4.0 in linux.

    Have you any idea??

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to read .doc file and replace string in that file using Qt in Linux?

    ActiveQt is a Qt wrapper of ActiveX, a Windows-only technology.

    Cheers,
    _

  5. #5
    Join Date
    Aug 2015
    Posts
    6
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to read .doc file and replace string in that file using Qt in Linux?

    Hello,

    Is there any other way to achieve this task??

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to read .doc file and replace string in that file using Qt in Linux?

    As I wrote before, you could look for a library that has I/O capabilities for the specific format (different versions of Word have different file formats).

    Or find a tool that can read/write it and be scripted, e.g. LibreOffice Writer.

    Cheers,
    _

  7. #7
    Join Date
    Aug 2015
    Posts
    6
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to read .doc file and replace string in that file using Qt in Linux?

    Ok Thanks.

Similar Threads

  1. how can i read a specific string from file?
    By sajastu in forum Qt Programming
    Replies: 5
    Last Post: 16th January 2015, 23:30
  2. XML, read file, string to enum.....
    By Speerfish in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2014, 10:34
  3. Replies: 8
    Last Post: 2nd January 2014, 14:44
  4. Replies: 8
    Last Post: 7th November 2010, 15:48
  5. setText using a string read from file
    By Splatify in forum Newbie
    Replies: 3
    Last Post: 28th October 2010, 15:39

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.