Excel to html java

Excel to html java

Allows converter to wrap content into two additional DIVs with tricky styles, so it will wrap across empty cells (like in Excel).

Methods inherited from class org.apache.poi.hssf.converter.AbstractExcelConverter

Methods inherited from class java.lang.Object

Constructor Detail

ExcelToHtmlConverter

public ExcelToHtmlConverter(org.w3c.dom.Document doc)

ExcelToHtmlConverter

Method Detail

main

public static void main(java.lang.String[] args) throws java.lang.Exception

Java main() interface to interact with ExcelToHtmlConverter Usage: ExcelToHtmlConverter infile outfile Where infile is an input .xls file ( Word 97-2007) which will be rendered as HTML into outfile

process

public static org.w3c.dom.Document process(java.io.File xlsFile) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException

process

public static org.w3c.dom.Document process(java.io.InputStream xlsStream) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException

process

public static org.w3c.dom.Document process(HSSFWorkbook workbook) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException

buildStyle

protected java.lang.String buildStyle(HSSFWorkbook workbook, HSSFCellStyle cellStyle)

getCssClassPrefixCell

public java.lang.String getCssClassPrefixCell()

getCssClassPrefixDiv

public java.lang.String getCssClassPrefixDiv()

getCssClassPrefixRow

public java.lang.String getCssClassPrefixRow()

getCssClassPrefixTable

public java.lang.String getCssClassPrefixTable()

getDocument

public org.w3c.dom.Document getDocument()

getStyleClassName

protected java.lang.String getStyleClassName(HSSFWorkbook workbook, HSSFCellStyle cellStyle)

isUseDivsToSpan

public boolean isUseDivsToSpan()

processCell

protected boolean processCell(HSSFCell cell, org.w3c.dom.Element tableCellElement, int normalWidthPx, int maxSpannedWidthPx, float normalHeightPt)

processColumnHeaders

protected void processColumnHeaders(HSSFSheet sheet, int maxSheetColumns, org.w3c.dom.Element table)

processColumnWidths

protected void processColumnWidths(HSSFSheet sheet, int maxSheetColumns, org.w3c.dom.Element table)

Creates COLGROUP element with width specified for all columns. (Except first if AbstractExcelConverter.isOutputRowNumbers() ==true)

Читайте также:  What is java drink

processDocumentInformation

processRow

protected int processRow(CellRangeAddress[][] mergedRanges, HSSFRow row, org.w3c.dom.Element tableRowElement)

processRowNumber

protected void processRowNumber(HSSFRow row, org.w3c.dom.Element tableRowNumberCellElement)

processSheet

processSheetHeader

processWorkbook

setCssClassPrefixCell

public void setCssClassPrefixCell(java.lang.String cssClassPrefixCell)

setCssClassPrefixDiv

public void setCssClassPrefixDiv(java.lang.String cssClassPrefixDiv)

setCssClassPrefixRow

public void setCssClassPrefixRow(java.lang.String cssClassPrefixRow)

setCssClassPrefixTable

public void setCssClassPrefixTable(java.lang.String cssClassPrefixTable)

setUseDivsToSpan

public void setUseDivsToSpan(boolean useDivsToSpan)

Allows converter to wrap content into two additional DIVs with tricky styles, so it will wrap across empty cells (like in Excel). Warning: after enabling this mode do not serialize result HTML with INDENT=YES option, because line breaks will make additional (unwanted) changes

Copyright 2021 The Apache Software Foundation or its licensors, as applicable.

Источник

How to Convert Excel and CSV Documents to HTML in Java

Join the DZone community and get the full member experience.

When it comes to organizing, structuring, and formatting data for everyday report presentations and report-sharing scenarios, Excel is decisively the world’s go-to spreadsheet solution. And that’s for good reason – Excel’s extensive and endlessly updated features are perfect for most of our manual data manipulation needs, allowing us to quickly generate stylish rows and columns with slick graphs and other forms of visuals. The open-XML .XLSX format also transitions nicely into plain text formats like CSV, making it equally straightforward to export and upload Excel’s tabular data to a broader range of compatible applications. Despite its myriad features and format conversion fluidity; however, document compatibility concerns are always lurking when we look to share Excel report content with the broadest possible audiences.

Of course, we don’t have to look very far to find a global, standardized solution to this long-standing challenge. Where fully formatted and finished data reports are concerned, PDF represents the ideal export format, owing largely to its universal compatibility and secure design. Excel and CSV documents converted to PDF format are viewable on any browser, and these PDFs can be formed as vector or raster files depending on the document creator’s personal preference.

The limitations of PDF conversions become apparent only when we extend our document conversion criteria to include universally compatible formats that are also equipped to continue the document’s design. Documents converted to vector PDF files can only return to their original format (or to text format when using OCR conversions), and this fundamental lack of any meaningful editing/formatting capabilities in PDF makes the format a dead-end for ongoing design iterations.

That’s where HTML conversions present a unique and exciting solution. Not only is HTML universally accessible (compatible with every platform and browser in the world), but it’s also extremely dynamic, allowing for the inclusion of vast visual customizations with CSS and interactive features with JavaScript. Tabular data converted to HTML can be reformatted and iterated upon endlessly using popular, up-to-date, and extremely well-documented markup elements.

Demonstration

In the remainder of this article, I’ll demonstrate two free API solutions with ready-to-run Java code examples that can be used to convert Excel and CSV documents to HTML format. Both allow form data input, so you can easily convert documents via absolute or relative file paths in your environment. These solutions will both return simple HTML text strings containing the converted document contents, making it straightforward to create and share accessible HTML files and further customize data visualizations in your resulting HTML code.

To take advantage of either API, start by installing the Java SDK. First, add a reference to the repository in pom.xml:

Источник

Convert Excel Files to HTML using Java

Excel spreadsheets allow you to store and well organize the data in tabular form. You can perform computations as well as generate different types of graphs and charts in order to analyze the data. However, in various scenarios, you may need to carry out Excel to HTML conversion to convert worksheets to HTML pages. For example, when embedding the content of the spreadsheets into web pages. In accordance with that, this article aims to cover how to convert Excel XLSX files to HTML programmatically using Java.

Excel to HTML Java Converter API#

Aspose.Cells for Java is a spreadsheet manipulation API that is designed to implement Excel automation within the Java applications. In addition, the API’s built-in spreadsheet converter engine allows you to convert XLSX files to HTML or other formats. You can either download the API or install it within your Maven-based applications.

 AsposeJavaAPI Aspose Java API https://repository.aspose.com/repo/  
 com.aspose aspose-cells 20.11  

Excel to HTML Java Conversion#

Excel to HTML conversion using Aspose.Cells is as easy as pie. Just load the Excel spreadsheet and save it as an HTML file. The following are the steps to convert an Excel XLSX file to HTML.

The following code sample shows how to convert an Excel file to HTML using Java.

Convert Excel XLSX to HTML with Tooltip#

In certain situations, the text exceeds the width of the cell in the worksheet. When you convert such a worksheet to an HTML page, some part of the text becomes hidden. For such scenarios, you can enable tooltips to view the exceeded text. The following are the steps to enable tooltips in Excel to HTML conversion.

  • Load the XLSX file using the Workbook class.
  • Create an instance of HtmlSaveOptions class.
  • Use HtmlSaveOptions.setAddTooltipText(true) to enable tooltips.
  • Save the file with .html extension using Workbook.Save(String, HtmlSaveOptions) method.

The following code sample shows how to enable tooltips in Excel to HTML conversion in Java.

Convert Excel XLS to HTML with Presentation Preference#

Aspose.Cells for Java provides an additional feature of setting presentation preference for the rendered HTML pages. You can use this feature to get a more attractive presentation of Excel workbooks when rendered to HTML. For this, you can set HtmlSaveOptions.setPresentationPreference(true) property. The following code sample shows how to enable presentation preference in Excel to HTML conversion.

Java XLSX XLS to HTML Converter — Try Aspose.Cells for Free#

You can use Aspose.Cells for Java for free without restrictions using a free trial license.

Conclusion#

In this article, you have learned how to convert Excel files to HTML using Java. Furthermore, you have seen how to enable tooltips and presentation preference in Excel to HTML conversion. You can explore more about the Java Excel API using the documentation.

See Also#

Источник

Java: Convert Excel to HTML

HTML files are Hypertext Markup Language files designed for displaying information in web browsers. In some cases, you might need to convert your Excel document to HTML in order to view it on the web. This article will demonstrate how to achieve this task programmatically in Java using Spire.XLS for Java.

Install Spire.XLS for Java

First of all, you’re required to add the Spire.Xls.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project’s pom.xml file.

  com.e-iceblue e-iceblue https://repo.e-iceblue.com/nexus/content/groups/public/    e-iceblue spire.xls 13.7.3   

Convert Excel to HTML

The following are the steps to convert an Excel file to HTML:

  • Create a Workbook instance.
  • Load an Excel file using Workbook.loadFromFile() method.
  • Save the file to HTML using Workbook.saveToFile() method.
import com.spire.xls.FileFormat; import com.spire.xls.Workbook; public class ConvertExcelToHTML < public static void main(String []args)< //Create a Workbook instance Workbook workbook = new Workbook(); //Load an Excel file workbook.loadFromFile("Sample1.xlsx"); //Save the file to HTML workbook.saveToFile("ToHtml.html", FileFormat.HTML); >>

Java: Convert Excel to HTML

Convert Excel to HTML with Image Embedded

The following are the steps to convert an Excel worksheet to HTML with image embedded:

  • Create a Workbook instance.
  • Load an Excel file using Workbook.loadFromFile() method.
  • Get the first worksheet using Workbook.getWorksheets().get() method.
  • Create a HTMLOptions instance and enable image embedding using HTMLOptions.setImageEmbedded() method.
  • Save the worksheet to HTML with image embedded using Worksheet.saveToHtml(String, HTMLOptions) method.
import com.spire.xls.Workbook; import com.spire.xls.Worksheet; import com.spire.xls.core.spreadsheet.HTMLOptions; public class ConvertExcelToHtmlWithImageEmbeded < public static void main(String []args)< //Create a Workbook instance Workbook workbook = new Workbook(); //Load an excel file workbook.loadFromFile("Sample2.xlsx"); //Get the first worksheet Worksheet sheet = workbook.getWorksheets().get(0); //Set embedded image as true HTMLOptions options = new HTMLOptions(); options.setImageEmbedded(true); //Save the worksheet to HTML sheet.saveToHtml("ToHtmlWithImageEmbeded.html", options); >>

Java: Convert Excel to HTML

Apply for a Temporary License

If you’d like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

See Also

Источник

Оцените статью