Had a quick question about the EPPlus library. Can it export an excel spreadsheet as an HTML page? The application I am writing needs to be able to do this.
You can use Spire.XLS which enables developers to convert Excel to other popular formats, such as PDF, XML, HTML, CSV, Image format etc
Its # Nuget, Install-Package Spire.XLS -Version 8.4.13
You could extract datatable from excel file using EPPlus and convert it to HTML using the code described here:
https://www.c-sharpcorner.com/UploadFile/deveshomar/export-datatable-to-html-in-C-Sharp/
Afterwards, you can export the html string to excel file as:
private void ExportToXLS(string data)
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=Your_File_Name.xls");
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
EnableViewState = false;
HttpContext.Current.Response.Write(HttpUtility.UrlDecode(data));
HttpContext.Current.Response.End();
}
EPPlus 6, released April 2022, has support for exporting ranges and tables to html with separate css. See these samples https://samples.epplussoftware.com/HtmlExport/
Related
I've generated a table using play's #{list} tag and get pretty decent results. Now I need to be able to generate and download an xls version of the table and have no idea what to do. Any pointers at all will be much appreciated
Well you have various options.
Excel will open HTML files. So instead of rendering your table as HTML you can it to stream it to the browser and set the content type as XLS.
While Excel will open it this it will still be an HTML file rather than an XLS(X) document.
You can generate as CSV from your data model and stream this to the browser. Again this will be a CSV rather than a proper XLS(X) document.
There also seem to be some solutions around which can do it using Javscript. See as a starting point: Generate excel sheet from html tables using jquery
Finally you can can use something like Apache POI or JXLS to generate a 'proper' xls(x) document and stream this to the browser. I have some code here that will export HTML to 'proper' xlsx file if this is the route you wish to go. Workflow is then to create some HTML from your data model and use this to convert to Excel rather than having to programmatically build the Excel document using POI. https://github.com/alanhay/html-exporter
I'm working on a project where we need to convert .OBJ models into .G3DJ (JSON) format on the fly. I've tried with this code I've founded in google code.
https://code.google.com/p/libgdx-users/wiki/ImportingModelsFromBlender
ObjLoader loader = new ObjLoader();
StillModel model = loader.loadObj(Gdx.files.internal("data/model.obj"), true);
G3dExporter.export(models, Gdx.files.absolute("data/model.g3d"));
But StillModel and G3DExporter cannot be found in libgdx.
Any ideas?
The libgdx-users wiki is not up to date. Converting an OBJ file to G3DJ (or G3DB) can be done using fbx-conv, which is a command line utility (you can call it from code if you like).
Also make sure to update to the nightly build. StillModel is no longer supported (and does not support the G3DJ (JSON) file format).
It is recommended not to use OBJ (although it is still supported). Instead use FBX (converted to G3Dx), which supports more functionality than OBJ.
Hey Related to your answer on Can I write files with HTML5/JS?
How would I modify this for say Excel or PDF. I tried but was unable to get it to work. I get a corrupt file downloaded when I change MIME to application/pdf
I am trying to link it to data stored in localstorage which I have all in a variable.
My current code is:
function setSaveFile(contents, file_name, mime_type) {
var a = document.getElementById('save');
mime_type = mime_type || 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; // text/html, image/png, et c
if (file_name) a.setAttribute('Log.xls', file_name);
a.href = 'data:'+ mime_type +';base64,'+ btoa(contents || 'Description' + ' ' + 'Notes' + ' ' + 'Date\n\n' + pdftimeLog);
}
I want to be able to export it as a CSV with each of those headings: DATE, description, notes in different cells. I want it mobile friendly.Thanks
Excellent Options for CSV Everyone:
http://snapshotmedia.co.uk/blog/jspdf
Is it possible to use any HTML5 fanciness to export local storage to Excel?
http://css-tricks.com/localstorage-examples/
Local Storage manipulation and possible sending
Thanks!
For a file to be a valid pdf or excelfile their contents need to conform to the standard that defines the respective format, just changing mimetypes won't do much good.
For PDF there's a library jspdf that might work for you.
I haven't seen a solution for Excel yet, it will be a whole lot harder as the (xls) file format is quite complicated, for the time being it's probably preferable to generate the file on the server.
As an alternative to CSV, it's also possible to write an Excel file by writing HTML to a file with a .xls extension. Excel opens it up based on the extension. Haven't yet explored how deeply it can paginate, format.
I'm trying to parse a .xlsx file exported from a google docs. Right now I'm not trying to access it online, I'm manually downloading it and copying inside my application.
I've read the tutorial provided online, and this is the code I have right now:
var contentBA:ByteArray = new ByteArray ();
var fileToLoad:File = File.applicationDirectory.resolvePath("textLabels.xlsx");
var stream:FileStream = new FileStream();
stream.open(fileToLoad, FileMode.READ);
stream.readBytes (contentBA, 0, contentBA.length);
var xls:ExcelFile = new ExcelFile();
xls.loadFromByteArray(contentBA);
trace ("N SHEETS ", xls.sheets.length);
but the number of sheets it's always 0. I tried to change the file and to load the most simple excel ever but it keeps saying 0.
Is it a problem of the ".xlsx" extension? Am I missing something?
AS3XLS was written for the old file format BIFF Office 97 style documents. I've written an XLSX exporter for my work on the AdvancedDataGrid but it's proprietary work so I can't share the code unfortunately. However I can give you some direction. The BIFF format used special codes for encoding things like formatting for cells or formulas, the binary format was seemingly meant to reduce the file size (and perhaps as a form of obfuscation). XLSX instead takes the more open XML approach, creating a BIFF file was complicated and was reverse engineered by the Open Office team before Microsoft ever published the spec for it, the newer XML formats are pretty well documented. Every new office file that ends with the x in it's extension is an archive (just like a zip file, you can open it with any archive tool) with a bunch of XML files inside that define the sheet. I basically took a sample sheet with nothing in it (opened Excel saved a new workbook) then pieced it apart and wrote AS3 classes that corresponded to each of the XML files and each implemented an interface that said it had to have a method to getXMLString() then I wrote a wrapper that would create all the objects and used the container pattern/traversal to build all the XML files needed and used the nochump AS3 zip library to package it together.
A useful tool for inspecting the xlsx or docx or whateverx files can be found here:
http://www.microsoft.com/en-us/download/details.aspx?id=5124
If you're on Mac discussion on one here:
http://openxmldeveloper.org/discussions/development_tools/f/27/p/1494/7453.aspx
Generally the site above was helpful
http://openxmldeveloper.org/
Documentation showing (minimal) examples
http://www.ecma-international.org/news/TC45_current_work/Office%20Open%20XML%20Part%203%20-%20Primer.pdf
NoChump's AS3 Zip library
http://nochump.com/blog/archives/15
Basically for more advanced features like tables or cell spanning I just attempted the change I wanted to be able to make programmatically in a simple Excel file then compared it against another without that new feature using the first tool linked above and implemented the change in the appropriate AS3 class (the one that corresponds to the XML file that changed).
It took about 2 weeks to get the organization of the classes solid but it's absolutely achievable.
ExcelFile is a class from a custom library and it says that supports Excel 2002-2003. What version of Excel do you use?
My company receives data from an external company via Excel. We export this into SQL Server to run reports on the data. They are now changing to PDF format, is there a way to reliably port the data from the PDF and insert it into our SQL Server 2008 database?
Would this require writing an app or is there an automated way of doing this?
As already mentioned - you will have to write an app to do this, but ideally you would be able to get the raw data from the external company rather than having to process the PDF.
However, if you do want to extract the data from the PDF, I've used iText and found it to be very powerful, reliable and most importantly - free. It comes in Java and .Net flavours - iTextSharp is the .Net version. It allows you to programatically manipulate PDF documents and it will expose the contents of the PDF to the application that you write.
It all depends on how they've included the data within the PDF. Generally speaking, there's two possible scenarios here:
The data is just a text object within a PDF. You'll need to use a tool to extract the text from the PDF then insert it into your database.
The data is contained within form fields in a PDF. You'll need to use a tool to extract data from the form fields and insert it into your database.
Hopefully scenario #2 applies to you because this is precisely what PDF forms are designed for. Scenario #1 is really just a hack that you'd only use if you didn't have any other options. Extracting plain text from a PDF isn't as easy or accurate as you might expect.
If you're receiving a PDF form then all you need to do is match up the right fields in the PDF form with the corresponding fields in your database and then suck in the data. This process could be entirely automated if you wrote your own application.
Would this require writing an app or
is there an automated way of doing
this?
Yes, both of these options would require writing an app or buying an app. If you write your own app then you'll need to find a third-party PDF library that supports retrieving data from form fields or extracting text from a PDF.
Disclaimer: I am affiliated with the makers of ByteScout PDF Extractor SDK tool
Just wanted to share some additional real-life scenarios for text data extraction from PDF:
Scanned image with no searchable text: should be processed by OCR engine (like free Tesseract from Google)
XFA forms: it is the subset of PDF which is supported mostly by Adobe tools. But the data can be extracted as XML data with low level PDF processing tools like iTextSharp or similar tools.
ZUGFeRD PDF files which are just PDF documents with the copy of a form data attached as XML file (which can be extracted with tools like this)
Text incorrectly encoded by some PDF generators (can be restored via OCR engine with some acceptable error rate though).
Using ItextSharp, do the following
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using iTextSharp.text.pdf;
protected void BtnSubmit_Click(object sender, EventArgs e)
{
String FilePath = #"GetFilePath";
StringBuilder sb = new StringBuilder();
PdfReader reader = new PdfReader(FilePath);
PdfStamper myStamp = new PdfStamper(reader, new FileStream(FilePath + "_TMP", FileMode.Create));
AcroFields form = myStamp.AcroFields;
if (form.GetField("GetFieldIdFromPDF") != null)
sb.Append(form.GetField("GetFieldIdFromPDF").ToString());
}
I think you will have to write an application for this. This question talks about extracting data from PDF. After this you can export the data to excel format so that you can preserve the existing import format.
Look for information on "Scraping" the data from the PDF. I believe Adobe has some tools that allow you to do this for simple text but I've not used them.
Honestly though, I would try to do anything you can to get this data in a raw format from your vendor.