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.
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,
_
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??
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,
_
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??
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,
_
Re: How to read .doc file and replace string in that file using Qt in Linux?