Style data and Export it to XLS/CSV/PDF using javascript - javascript

I have been searching a way to export data to xls/csv/pdf and found many threads talking about this topic:
Angular JS - How to export Javascript Object to XLS file ?
Export to xls using angularjs
However, none of these methods support styling data; text color, background color, regular/bold/italic, etc. For example, I wanted to style a header row background of a xls file to be gray. Moreover, most of them don't support in Safari/IE9.
Is there any library for exporting these types of data, which support styling data and also support all modern browsers?

For styling you need to use other available API's/.jar files
Apache POI for Excel
IText for PDF
I doubt if any JS file provide support for designing Excel and PDF.

You should take a look at the Microsoft Office XML Formats here (https://en.wikipedia.org/wiki/Microsoft_Office_XML_formats)
You can construct a variable with the xml tags, then output it as XLSX.

Related

Javascript (Angular Js) exporting Json as excel (with letters in fonts)

I am trying to implement to Json to Excel exporting in javascript. I am using angular js. I was to able to generate Json to CSV but i cant not retain font(bold) and macros in CSV (because its csv).
Is there any opensource in the market for Json to Excel conversion by retaining font colours for the text.
There is an interesting project on github called Excel Builder (.js)
that offers a client-side way of downloading Excel xlsx files and includes options for formatting the Excel spreadsheet.
https://github.com/stephenliberty/excel-builder.js
You may encounter both browser and Excel compatibility issues using this library, but under the right conditions, it may be quite useful.
The demos on github project with less Excel options but less worries about Excel compatibility issues can be found here: ExcellentExport.js
https://github.com/jmaister/excellentexport
The demos seem to hold some promise.
http://excelbuilderjs.com/index.html
If you are using AngularJS, there is ng-csv:
a "Simple directive that turns arrays and objects into downloadable CSV files".

How to export excel files using excel-builder.js

I have been working on a project with Angular 1 which will require me to build functions to export excel file with some formatting from browser. I found excel-builder.js can be very powerful and useful, but the current tutorial website: http://excelbuilderjs.com/ is not accessible anymore. Can anyone provide me any documentation, especially for excel file formatting?
Thank you very much!
you can make excel from html table.As i create a fiddle here http://jsfiddle.net/dssoft32/WPpDm/36/
All colors and styles will work inline css. you can custom as you want. I have also user the Filesaver.js to download Blob object.

Convert HTML Report to PDF

I want convert an HTML report to PDF. I know that there are so many libraries are available for this purpose. But the HTML report contains so many graphs created using Jqplot. I want to include these graphs in the PDF also. If you are familiar with any library which also convert graphs to PDF, please give me the reference.
you can use bullzip pdf printer it creates a virtual pdf printer that can transform your HTML content to a pdf file from the browser:
http://www.bullzip.com/
you can also find a lot of useful tools right there!
I don't have experience with Jqplot, but I have successfully converted html pages which contain pie charts from Google Charts (completely javascript generated) to pdf.
I used wkhtmltopdf - it's a commandline tool but there are wrapper classes for php and some others I believe.
I'm sure you could find something applicable with a bit of googling but this looks promising: https://github.com/mikehaertl/phpwkhtmltopdf

Jquery script for document preview?

Do you know any components from jQuery with which you can preview .doc,.pdf,.jpg .... files in browser ?
Thanks
If you really want to keep it all native inside the browser you can display images on their own and pdfs with pdf.js.
If you only need to display it somehow I advise you to look at Google docs viewer (officially discontinued, see below) which allows you lots of different files and which you can next embed in one of the scripts altschuler mentioned. (See my comment to his answer why those tools alone don't do the trick)
Supported file types by google docs viewer
Microsoft Word (.DOC and .DOCX)
Microsoft Excel (.XLS and .XLSX)
Microsoft PowerPoint (.PPT and .PPTX)
Adobe Portable Document Format (.PDF)
Apple Pages (.PAGES)
Adobe Illustrator (.AI)
Adobe Photoshop (.PSD)
Tagged Image File Format (.TIFF)
Autodesk AutoCad (.DXF)
Scalable Vector Graphics (.SVG)
PostScript (.EPS, .PS)
TrueType (.TTF)
XML Paper Specification (.XPS)
Archive file types (.ZIP and .RAR)
Although I wouldn't recommend this usage on production or professional systems, you can still use the system as described here.
I think you're looking for a lightbox feature. Lightbox is the common name for (pre)viewing things in an overlay, so to say.
There are a great deal to choose from, here's a few:
http://gettopup.com (try the #2 example, this looks a lot like quicklook).
http://leandrovieira.com/projects/jquery/lightbox
http://jacklmoore.com/colorbox
How you want to show .doc and .pdf files is another issue.

What is the best way to convert HTML into Excel

I have an HTML page which has a flash chart(FusionCharts) and HTML table. I need to convert this whole thing into Excel. HTML table should be displayed in cells of excel sheet. Flash chart can be displayed as an image.
Is there any open source API that we could use for achieving this. Could you let me know what are the possible options.
Can this be done by using javascript alone.
The HTML table is relatively easy. You can download the page, parse the HTML (there are various HTML parsing libraries available), extract the table and convert it into CSV (which Excel can load), or directly create an Excel file, e.g. using Java POI, as suggested above.
The Flash part is significantly harder. There are quite a few tools available to capture flash to an image, you'd need to use one of them. This can be tricky, as Flash might be interactive, so you'd possibly have to remote-control the Flash part so it shows the right image before capturing. Hard to tell without more info.
That said, screen-scraping (which is what you're doing) is always labour-intensive and fragile. You should really push for a better interface to get your data from, it will save loads of hassle in the long run.
Just set the content type of the page to "application/vnd.ms-excel". If the html page is just a table it will open with excel and look perfect. You can even add background colors and font styles.
Try some of these content types
application/excel
application/vnd.ms-excel
application/x-excel
application/x-msexcel
Excel can convert HTML tables by default. The easiest way to force it to do this is to save the HTML file with an XLS extension. Excel will then open the XLS as if it were its native workbook.
There's a very good Java POI api that would let you do that, but it's Java.
http://poi.apache.org/
If you're on Win32 you can also use Excel's COM api, there are quite a few tutorials on the net.
I cannot offer any advice on the Flash part, but I have done HTML table to Excel many times. Yes, Excel can open HTML tables but most HTML tables out there have extraneous crap in them that can make it fragile to consistently parse the tables.
CPAN module HTML::TableExtract is a wonderful module that allows you to focus on the non-presentation specific aspects of the table you are trying to extract. Just specify the column headings you are interested in and maybe specify the title or class of the table and you are mostly set. You might have to post process the rows returned a little, but that is considerably easier than dealing with the underlying tag soup in all its glory.
Further, for output to Excel format, stick with Spreadsheet::WriteExcel rather than the OLE interface. That way, you do not depend on having Excel installed for your program to work and things go a little faster.
Make sure you specify the data type of cells if you do not want content to be changed automatically by Excel upon opening the files (another reason I do not like sending around CSV files). Use a configuration file for formatting information so that you can change how the spreadsheet looks without having to change the program.
You can always use Excel's built-in charting facilities to replace the web site graphs.
This combination has enabled me to generate pretty good looking documents comprising several hundreds of megabytes of scraped data (with logos and image links etc) using just a few hundred lines of Perl and a couple of days' work.
What you're trying to do is fragile and difficult to maintain. You should attempt to create a csv feed to fetch the data. All it takes is for someone to come along and modify the HTML and your scraper will throw up on it (probably years after anyone remembers how your program works).
Try to get CSV and image data from the original source (ie, database or whatever) and build the Excel file from that.
I will add to SpliFF's answer that when you have your data as a CSV file you can set the mime type of the page to application/vnd.ms-excel which will open the page in Excel

Categories

Resources