Insert at word file excel table - php

I need to generate Word document using PHP. I have html, save it as doc-file, but now I need to insert in this file excel table. How can I do it with html content, or I need some classes to do it?

There is an excellent PHP class for creating Excel documents. It is called php-export-data by Eli Dickinson, http://github.com/elidickinson/php-export-data.
Also you can check this stackoverflow question: Alternative for PHP_excel
However, this is some sort of advanced task, you better be prepared.

Related

how would one go about converting HTML table to Spreadsheet with JavaScript and/or PHP? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I export tables to excel from a webpage
EDIT: Just to clarify, it does not HAVE to be an Excel file, but it has to be a spreadsheet file which is able to be opened/edited in Excel.. So whatever would accomplish this most easily is the answer I seek :)
I need to convert an HTML table to some sort of downloadable spreadsheet (preferably for Office Excel). I can do this in jQuery, but would prefer to do it in plain JavaScript. I've searched around and have found a lot of info about doing the reverse (spreadsheet->html), but I need to create a downloadble spreadsheet file of a dynamically built table. Any points for how I could accomplish this would be much appreciated! :)
Don't do this in JavaScript. You need to do this in a server-side scripting language like PHP.
The easiest way to prepare data for importing into a spreadsheet is going to be creating a CSV file. Here's an example CSV file which will open fine in Excel:
column_a,column_b
1,2
5,7
8.988,abcdef
CSV files are just plain text, with the fields separated by commas, so they are easy to create. If the data in your fields needs to contain commas, double quote marks, newlines, or a few other special cases, then things get more tricky.
If you really want to create an Excel-format spreadsheet, this is pretty difficult and you're going to want the help of a library. Here's how I would find a PHP Excel library: http://google.com/search?q=php+create+excel+spreadsheet
You can't do this with JavaScript because it cannot create a downloadable file.
You must do this on the server. Any HTML page that is a table will automatically be converted BY EXCEL ITSELF if you send out the correct MIME header before streaming out the HTML file.
You can't do it all in Javascript. You can write a jQuery function to convert a table to something like a CSV format, but you won't be able to tell the browser to let the user download it. You'll have to POST it to a server which can then serve back the file.
See this question for details.
I can be mistaken, but it may be possible using data: URI scheme
<a href="data:text/csv;charset=utf8;base64,...encoded_data...">
download as Excel
</a>
It is not cross-browser, but can help.

Convert HTML & CSS to DOC(X)?

Is there some utility that could be called via command line to produce a doc(x) file? The source file would be HTML and CSS.
I am trying to generate Word documents on the fly with PHP. I am only aware of phpdocx library, which is very low level and not much use for me (I already have one poor implementation of Word document generation).
What I need from a document:
TOC
Images
Footers/Headers (they could be manually made on each HTML page)
Table
Lists
Page break (able to decide what goes to which page, eg one HTML file per page, join multiple HTML files to produce the entire document.)
Paragraphs
Basic bold/etc styles
I didn't find PHPDOCX very useful either. An alternative could be PHPWord, i think it covers what you need. According the website it can do these things:
Insert and format document sections
Insert and format Text elements
Insert Text breaks
Insert Page breaks
Insert and format Images and binary OLE-Objects
Insert and format watermarks (new)
Insert Header / Footer
Insert and format Tables
Insert native Titles and Table-of-contents
Insert and format List elements
Insert and format hyperlinks
Very simple template system (new)
In your case that isn't enough, but there is a plugin available to convert (basic) HTML to Docx and it works very good in my opinion. http://htmltodocx.codeplex.com/
I am using this for a year or two now and am happy with it. Altough i have to add that the HTML can't be to complex.
The way I usually do these is to have a word document template file with the parts I want to replace using keywords (usually something like "{FIRSTNAME}").
This allows you to read the file via PHP then simply do str_replace on all the parts you want to replace, then write that to another file.
Dynamic tables using this method are a bit more tricky, as you need a sub template for a row, which you can then include inside the main template as many times as required.
I'm not sure if this is the best solution, it's always seemed very fiddly to me and every time I'm asked to do this I get frustrated with it, but I guess it works. So if anyone knows a better solution I'd love to hear it too!

How can i take an excel file, parse it contents and store the column's data of excel sheet in my database column?

There is one excel sheet which contains student name, rollno etc. How can i parse the contents of excel file and store that in my sql database?
You are looking for PHPExcel library i believe.
http://phpexcel.codeplex.com/
use this class to read the excel files
http://sourceforge.net/projects/phpexcelreader
If you want to do it directly from the Excel file, rather than create an intermediate CSV using Excel's "Save As" options, then look at libraries such as PHPExcel that can read the xls binary format and make the data accessible to your PHP script.
I'd recommend to you that you save it as csv, it's much more easier and less hacking to upload it to the database
here is simple a sample
http://www.bradino.com/php/csv-upload-to-database/
PHPExcel is one of the best PHP classes i have ever worked with. In addition to parsing and reading files of all Excel variations (including csv) the output to Excel 2007 + is excellent.
Be sure to look at the documentation and examples...they will get you up to speed very quickly

How to extract data from a PDF and store in MySQL

I have a PDF document that contains data that I would like to extract and store in a MySQL database. Could anyone give me some guidance or perhaps sample PHP code?
There's some basic code here for performing text extraction from a PDF. Might work for you. For commercial libraries, check out pdflib which I believe can do similar extraction.
Once you have the data, it's up to you to massage that into MySQL INSERT statements to create your database.
I often use the FPDF library to create PDF documents via a PHP script. Plenty of examples and documentation here: http://www.fpdf.org/
What do you wanna do ?
If you want to store the PDF in a MySQL database, i recommand you to store the pdf in a directory and the path to the pdf in the mysql database.
Or you can store file_get_contents($pathToThePDF) in the db but I don't think it's a good idea.
If you want to create with PHP a PDF with data from a MySQL db, i also use fpdf (like rascher) to do that and it works well + there are many example on the website.

exporting mysql data to ODF with php

I would like to know if someone triend exporting data from MySQL to an ODF format ?
Any information / documentation would be very much appreciated.
I am going to try to export a MySQL result set to ODF spreadsheet if possible.
You could try looking at this: http://www.phpclasses.org/browse/package/4398.html
However looking at the source code it doesn't look great and has lots of hard coded xml strings
Another option to create OOo files with PHP is tbsOOo; however, it is mainly a templating engine.
This class allows to create OpenOffice
documents dynamically by separating
display formatting from logic and
data. In practice, you create a
template using OpenOffice with the
TinyButStrong tags. Then you create a
PHP script that merges the template
with a data source to get a new
OpenOffice document.
There is also: OpenDocument PHP which is more complex and can create the files dynamically.

Categories