Welcome Guest, Not a member yet? Register   Sign In
Exporting to microsoft word documents
#1

[eluser]simpleCoder[/eluser]
Does anyone know how to export html to Microsoft word .I have this project that requires generation of performance reviews in microsoft word so users can edit their review further. At the moment , i am only using PDF libraries .
#2

[eluser]Crafter[/eluser]
I know there is a solution using COM objects, but there are Windows specific, and I'm not windows-savy.

For a true cross platform solution, I used RTF files with placeholders, where I performed string replacements.

I used a similar approach fro an Excel file, where I conrted the Excel file to an XML file, then placed placeholders in significant positions.

The XML route will take macros etc, acroos, whereas the RTF route is for pure formatting.

The elegant way is move away from Word and do the report in OpenOffice.

EDIT:
Excuse me, but after posting I noticed you asked for a conversion of HTML to Word.
My suggested solutions may not be the best approch.

However, just try forcing the page download as a word document using headers and Word should open the file ok.
#3

[eluser]Derek Allard[/eluser]
Quote:However, just try forcing the page download as a word document using headers and Word should open the file ok.
That is a great solution Crafter - elegant. John, I'd love to know if you tried it, and if you found any issues with it, but I think that Word can in fact open html docs, so that should be very nice.

For the record, I think it would be
Code:
header("Content-Type: application/msword");.
// OR
header("Content-Type: application/vnd.ms-word");.
#4

[eluser]Crafter[/eluser]
Hey Derek, long time...

Quite correct on your header.

Here's how I force the page into the office application (and give it a file name too!

Code:
header("Content-Type: application/vnd.ms-word");
   header("Expires: 0");
   header("Cache-Control:  must-revalidate, post-check=0, pre-check=0");
   header("Content-disposition: attachment; filename=\"mydocument_name.doc\"");

   $output = $this->load->view("myreport", $mydata);
   echo $data;
   exit;

  // ...or just use
  // ...$this->load->view("myreport"< $mydata, true);
#5

[eluser]bonza[/eluser]
I've done a fair bit of work creating MSWord format documents from (Linux) web apps.

Office 2003 has a native XML format which means you don't have to use COM objects to create Word docs. It's relatively simple - create a template in word to get the formatting correct, create place holders for your required text and then substitute the dynamic content at run time.

Alternatively, you could create the whole document on the fly using template stubs which you can call as needed.
#6

[eluser]llbbl[/eluser]
Use open document format, its better Wink
#7

[eluser]xico[/eluser]
[quote author="Crafter" date="1190977145"]Hey Derek, long time...

Quite correct on your header.

Here's how I force the page into the office application (and give it a file name too!

Code:
header("Content-Type: application/vnd.ms-word");
   header("Expires: 0");
   header("Cache-Control:  must-revalidate, post-check=0, pre-check=0");
   header("Content-disposition: attachment; filename=\"mydocument_name.doc\"");

   $output = $this->load->view("myreport", $mydata);
   echo $data;
   exit;

  // ...or just use
  // ...$this->load->view("myreport"< $mydata, true);
[/quote]

I haven't used ur code but it seems that it will work , can you please tell me what will be in the $mydata variable
#8

[eluser]Crafter[/eluser]
xico,

$nydata will be the content of your document. In the context of the thread, it will be formatted HTML text that will be loaded into your word-processor.
#9

[eluser]Bikun[/eluser]
Has anybody managed to save Word files in a UTF format?

I tried to use
Code:
header("Content-Type: application/msword; charset=utf-8");

but files still seem to save in a wrong format.
#10

[eluser]moodsey211[/eluser]
Hi guys.

Actually you could generate a word document using it's XML format.

Microsoft XML formats

It also works for excel. I've been doing this for quite sometime now. You generate the xml file and download it with a dot doc extension. MS Word would then parse it as though it was really a doc file.

Hope that helps.

Best regards,
moodsey211

Note:
I've only tried this using the following MS Office version:
2003
2007




Theme © iAndrew 2016 - Forum software by © MyBB