We are glad to announce the release of Spire.PDFViewer 7.1. This version Support rotating page when viewing PDF by PdfViewer. It also fixes some known issues such as the PDF content displayed was incorrect. More details are listed below.

Here is a list of changes made in this release

Category ID Description
New feature SPIREPDFVIEWER-526 Supports rotating page when viewing PDF by PdfViewer.
Bug SPIREPDFVIEWER-205
SPIREPDFVIEWER-206
SPIREPDFVIEWER-532
Fixes the issue that the PDF content displayed was incorrect.
Bug SPIREPDFVIEWER-219
SPIREPDFVIEWER-524
SPIREPDFVIEWER-528
Fixes the issue that the PDF content displayed was blank.
Bug SPIREPDFVIEWER-378 Fixes the issue that the PDF text content displayed was garbled.
Bug SPIREPDFVIEWER-469 Fixes the issue that the scroll bars still existed after setting "fitpage" for the zoom mode.
Bug SPIREPDFVIEWER-518 Fixes the issue that the application threw "ArgumentOutOfRangeException" after changing the zoom mode.
Bug SPIREPDFVIEWER-519
SPIREPDFVIEWER-536
Fixes the issue that the PDF content displayed was incorrect when using in WPF project.
Bug SPIREPDFVIEWER-520 Fixes the issue that the PDF image was covered.
Bug SPIREPDFVIEWER-543 Fixes the issue that some PDF content can not be displayed.
Click the link to get Spire.PDFViewer 7.1:
More information of Spire.PDFViewer new release or hotfix:

We are glad to announce the release of Spire.PDF 8.1.4. This version supports converting OFD to PDF and image, and support setting layer print properties, as well as supports adding InkAnnotation. In addition, it fixes some known issues such as the extracted text was incorrect. More details are listed below.

Here is a list of changes made in this release

Category ID Description
New feature - Supports converting OFD to PDF and image.
OfdConverter converter = new OfdConverter("inputFile");
converter.ToPdf("outputFile");
converter.ToImage(pageIndex);
converter.ToImage(pageIndex, dpiX, dpiY); 
New feature SPIREPDF-2732 Supports setting layer print properties.
converter.ToLinearizedPdf("Linearized.pdf");
 PdfDocument pdfDoc = new PdfDocument();
 pdfDoc.LoadFromFile(inputFile);
 Spire.Pdf.PdfPageBase page;
 pdfDoc.FileInfo.IncrementalUpdate = false;
 string MvAddedlaverName1 = "GorLaverPagel";
 for (int iPage = 0; (iPage <= (pdfDoc.Pages.Count - 1)); iPage++)
 {
     page = pdfDoc.Pages[iPage];
     Spire.Pdf.Graphics.Layer.PdfLayer wtLaver_1 = pdfDoc.Layers.AddLayer(MvAddedlaverName1);
     wtLaver_1.ViewState = LayerViewState.Allways;
     wtLaver_1.PrintState = LayerPrintState.Nerver;
     wtLaver_1.ExportState = LayerExportState.ExportWhenVisible;
     Spire.Pdf.Graphics.PdfCanvas gPdfCanvas_1 = wtLaver_1.CreateGraphics(page.Canvas);
     gPdfCanvas_1.SetTransparency(0.4f);
     gPdfCanvas_1.DrawString(tStatusString, new PdfFont(PdfFontFamily.Helvetica, 28), new PdfSolidBrush(Color.Black), new System.Drawing.PointF(((page.Size.Width - 265) - (524 / 2)), (page.Size.Height - (50 - 127))));
     wtLaver_1.CreateGraphics(gPdfCanvas_1);
     gPdfCanvas_1.SetTransparency(1);
 }
 pdfDoc.SaveToFile(outputFile, FileFormat.PDF);
 pdfDoc.Close();
New feature SPIREPDF-2871 Supports adding InkAnnotation.
System.Collections.Generic.List<int[]> inkList = new System.Collections.Generic.List<int[]>();
 int[] intPoints = new int[]
 {
       100,800,
       200,800,
       200,700
 };
 inkList.Add(intPoints);
 PdfInkAnnotation ia = new PdfInkAnnotation(inkList);
 ia.Color = Color.LightBlue;
 ia.Border.Width = 12;
 ia.Opacity = 0.3f;
 ia.Text = "e-iceblue";
 pdfPage.AnnotationsWidget.Add(ia);
Bug SPIREPDF-974 Fixes the issue that it was failed to add .emf file to PDF.
Bug SPIREPDF-3457 Fixes the issue that the items of XfaChoiceListField was unable to get.
Bug SPIREPDF-4821 Fixes the issue that the extracted text was incorrect.
Bug SPIREPDF-4849 Fixes the issue that the content was lost after replacing text.
Bug SPIREPDF-4853 Fixes the issue that the position of the found text was incorrect.
Bug SPIREPDF-4855 Fixes the issue that the custom time of the digital signature was incorrect.
Bug SPIREPDF-4861 Fixes the issue that some content was lost after copying annotation to other page.
Bug SPIREPDF-4871 Fixes the issue that the added PdfRubberStampAnnotation didn't display in output PDF.
Bug SPIREPDF-4875 Fixes the issue that the application threw "System.ArgumentOutOfRangeException" after setting grid RowSpan.
Click the link to download Spire.PDF 8.1.4
More information of Spire.PDF new release or hotfix:
Wednesday, 19 January 2022 07:07

Java: Replace Fonts in a PDF Document

The use of appropriate fonts is one of the key elements of making successful documents. For example, we typically use different fonts for headings and paragraphs in order to create distinction and achieve a visually pleasing effect. When you receive a PDF document where the fonts are properly used, you may wish to change them. In this article, you’ll learn how to replace the fonts being used in a PDF document using Spire.PDF for Java.

Install Spire.PDF for Java

First of all, you're required to add the Spire.Pdf.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.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.pdf</artifactId>
        <version>5.1.1</version>
    </dependency>
</dependencies>

Replace All Used Fonts in a Document

A PDF document may use multiple fonts, and each font may have a different font size. When replacing these fonts, make sure that the font size does not change. Otherwise, the generated content may overlap or become disordered. The following are the steps to replace all used fonts in a document using Spire.PDF for Java.

  • Create a PdfDocument object.
  • Load a sample PDF file using PdfDocument.loadFromFile() method.
  • Get all used fonts in the document using PdfDocument.getUsedFonts() method.
  • Loop through the used fonts. Get the size of a specific font using PdfUsedFont.getSize() method.
  • Create a new font based on the size obtained, and replace the old font with the new font using PdfUsedFont.replace() method.
  • Save the document to a different PDF file using PdfDocument.saveToFile() method.
  • Java
import com.spire.pdf.PdfDocument;
import com.spire.pdf.graphics.PdfFont;
import com.spire.pdf.graphics.PdfFontFamily;
import com.spire.pdf.graphics.PdfFontStyle;
import com.spire.pdf.graphics.fonts.PdfUsedFont;

public class ReplaceAllFonts {

    public static void main(String[] args) throws Exception {

        //Create a PdfDocument object
        PdfDocument doc = new PdfDocument();

        //Load a sample PDF file
        doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\Fonts.pdf");

        //Get all used fonts in the document
        PdfUsedFont[] fonts = doc.getUsedFonts();

        //Travers all used fonts 
        for (PdfUsedFont font: fonts
             ) {

            //Get the font size
            float fontSize = font.getSize();

            //Create a new font
            PdfFont newfont = new PdfFont(PdfFontFamily.Times_Roman, fontSize, PdfFontStyle.Italic);

            //Replace the current font with the new font
            font.replace(newfont);

        }

        //Save the changes to a different PDF file
        doc.saveToFile("output/ReplaceAllFonts.pdf");
    }
}

Java: Replace Fonts in a PDF Document

Replace a Specific Font with a Different Font

The PdfDocument.getUsedFonts() method returns a collection of the fonts used in a PDF document. To identify a specific font from the fonts collection, use the PdfUsedFont.getName() method. The following are the steps to replace a specific font with a different font.

  • Create a PdfDocument object.
  • Load a sample PDF file using PdfDocument.loadFromFile() method.
  • Get all used fonts in the document using PdfDocument.getUsedFonts() method.
  • Loop through the used fonts, determining if a certain font is "Calibri".
  • Get the font "Calibri" and get its size using PdfUsedFont.getSize() method.
  • Create a new font based on the size obtained, and replace the font "Calibri" with the new font using PdfUsedFont.replace() method.
  • Save the document to a different PDF file using PdfDocument.saveToFile() method.
  • Java
import com.spire.pdf.PdfDocument;
import com.spire.pdf.graphics.PdfFont;
import com.spire.pdf.graphics.PdfFontFamily;
import com.spire.pdf.graphics.PdfFontStyle;
import com.spire.pdf.graphics.fonts.PdfUsedFont;

public class ReplaceSpecificFontWithNewFont {

    public static void main(String[] args) throws Exception {

        //Create a PdfDocument object
        PdfDocument doc = new PdfDocument();

        //Load a sample PDF file
        doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\Fonts.pdf");

        //Get all fonts used in the document
        PdfUsedFont[] fonts = doc.getUsedFonts();

        //Travers all used fonts 
        for (PdfUsedFont font: fonts
        ) {

            //Determine if a font’s name is "Calibri"
            if(font.getName().equals("Calibri")){

                //Get the font size
                float fontSize = font.getSize();

                //Create a new font
                PdfFont newfont = new PdfFont(PdfFontFamily.Times_Roman, fontSize, PdfFontStyle.Italic);

                //Replace the font "Calibri" with the new font
                font.replace(newfont);
            }

        }

        //Save the changes to a different PDF file
        doc.saveToFile("output/ReplaceSpecificFont.pdf");
    }
}

Java: Replace Fonts in a PDF Document

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.

We are excited to announce the release of Spire.PDF for Android via Java 4.1.0. This version fixes the issue that the application threw "File Name : "?|"cannot be represented in dex format" when using product in high Gradle and SDK versions. More details are listed below.

Here is a list of changes made in this release

Category ID Description
Bug SPIREPDF-4032
SPIREPDF-4187
Fixes the issue that the application threw "File Name : "?|"cannot be represented in dex format" when using product in high Gradle and SDK versions
Click the link below to download Spire.PDF for Android via Java 4.1.0
Tuesday, 18 January 2022 07:01

Java: Hide or Show Rows or Columns in Excel

Sometimes we need to hide some rows and columns in Excel worksheets so that the data appears completely on one screen. At other times, we need to show all the hidden rows and columns to view the data completely. In this article, you will learn how to hide and show rows or columns in Excel in Java applications from the following four parts.

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.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.xls</artifactId>
        <version>5.1.5</version>
    </dependency>
</dependencies>

Hide Rows and Columns

The detailed steps are listed as below.

  • Create a Workbook instance and load a sample Excel document using Workbook.loadFromFile() method.
  • Get a specified worksheet using Workbook.getWorksheets().get() method.
  • Hide a specific column using Worksheet.hideColumn(int columnIndex)method.
  • Hide a specific row using Worksheet.hideRow(int rowIndex) method.
  • Save the document to file using Workbook.saveToFile() method.
  • Java
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;


public class HideRowsColumns {
    public static void main(String[] args) throws Exception {

        //Load the sample document
        Workbook wb = new Workbook();
        wb.loadFromFile("Sample.xlsx ");

        //Get the first worksheet
        Worksheet sheet = wb.getWorksheets().get(0);

        //Hide the third column
        sheet.hideColumn(3);

        //Hide the third row
        sheet.hideRow(3);

        //Save the document
        wb.saveToFile("HideRowsColumns.xlsx", ExcelVersion.Version2016);
    }
}

Java: Hide or Show Rows or Columns in Excel

Show Hidden Rows and Columns

  • Create a Workbook instance and load a sample Excel document using Workbook.loadFromFile() method.
  • Get a specified worksheet using Workbook.getWorksheets().get() method.
  • Show a hidden column using Worksheet.showColumn(int columnIndex)method.
  • Show a hidden row using Worksheet.showRow(int rowIndex) method.
  • Save the document to file using Workbook.saveToFile() method.
  • Java
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;


public class ShowRowsColumns {
    public static void main(String[] args) throws Exception {

        //Load the sample document
        Workbook wb = new Workbook();
        wb.loadFromFile("HideRowsColumns.xlsx ");

        //Get the first worksheet
        Worksheet sheet = wb.getWorksheets().get(0);

        //Unhide the third column
        sheet.showColumn(3);

        //Unhide the third row
        sheet.showRow(3);

        //Save the document
        wb.saveToFile("ShowRowsColumns.xlsx", ExcelVersion.Version2016);
    }
}

Java: Hide or Show Rows or Columns in Excel

Hide Multiple Rows and Columns

  • Create a Workbook instance and load a sample Excel document using Workbook.loadFromFile() method.
  • Get a specified worksheet using Workbook.getWorksheets().get() method.
  • Hide multiple columns using Worksheet.hideColumns(int columnIndex, int columnCount)method.
  • Hide multiple rows using worksheet.hideRows(int rowIndex, int rowCount) method.
  • Save the document to file using Workbook.saveToFile() method.
  • Java
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;


public class HideMultiRowsColumns {
    public static void main(String[] args) throws Exception {

        //Load the sample document
        Workbook wb = new Workbook();
        wb.loadFromFile("Sample01.xlsx ");

        //Get the first worksheet
        Worksheet sheet = wb.getWorksheets().get(0);

        //Hide multiple columns
        sheet.hideColumns(2,2);

        //Hide multiple rows
        sheet.hideRows(3,3);

        //Save the document
        wb.saveToFile("HideMultiRowsColumns.xlsx", ExcelVersion.Version2016);
    }
}

Java: Hide or Show Rows or Columns in Excel

Show Multiple Rows and Columns

  • Create a Workbook instance and load a sample Excel document using Workbook.loadFromFile() method.
  • Get a specified worksheet using Workbook.getWorksheets().get() method.
  • Loop through the rows and find the hidden rows using Worksheet.getRowIsHide() method.
  • Show all hidden rows using Worksheet.showRow(i) method.
  • Save the document to file using Workbook.saveToFile() method.
  • Java
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;


public class ShowMultiRowsColumns {
    public static void main(String[] args) throws Exception {

        //Load the sample document
        Workbook wb = new Workbook();
        wb.loadFromFile("HideMultiRowsColumns.xlsx");

        //Get the first worksheet
        Worksheet sheet = wb.getWorksheets().get(0);

        //Traverse all the rows 
        for (int i = 1; i <= sheet.getLastRow(); i++) {

                //detect if the row is hidden
                if (sheet.getRowIsHide(i)) {

                    //Show the hidden rows
                    sheet.showRow(i);
                }
            }

        //Traverse the columns and show all the hidden columns
        for (int j = 1; j <= sheet.getLastColumn(); j++) {
            if (sheet.getColumnIsHide(j)) {
                sheet.showColumn(j);
            }

            //Save the document
            wb.saveToFile("ShowMultiRowsColumns.xlsx", ExcelVersion.Version2016);
        }
    }
}

Java: Hide or Show Rows or Columns in Excel

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.

We are happy to announce the release of Spire.XLS for Java 5.1.5. This version enhances the conversion from Excel to PDF/HTML/images, as well as HTML to Excel. In addition, it fixes some known issues such as the application threw an exception when loading excel file. More details are listed below.

Here is a list of changes made in this release

Category ID Description
Bug SPIREXLS-3540 Fixes the issue that the application threw an exception when loading excel file.
Bug SPIREXLS-3561 Fixes the issue that the page number position was incorrect after converting excel file to PDF.
Bug SPIREXLS-3574 Fixes the issue that some chart data lost after converting excel file to PDF.
Bug SPIREXLS-3587 Fixes the issue that the application threw "NullPointerException" when converting Html to excel.
Bug SPIREXLS-3600 Fixes the issue that the OLE object obtained was incorrect.
Bug SPIREXLS-3603 Fixes the issue that the content format was incorrect after converting excel file to Html.
Bug SPIREXLS-3607 Fixes the issue that the content was incorrect after converting excel file to image.
Bug SPIREXLS-3608 Fixes the issue that the application threw error ("utf-8 http-equiv=Content-Type is not a supported encoding") when loading a Html file.
Bug SPIREXLS-3609 Fixes the issue that the application threw "NullPointerException" when getting excel cell formula value.
Click the link to download Spire.XLS for Java 5.1.5

We are pleased to announce the release of Spire.Doc for Java 5.1.9. This version enhances the conversion from Word to PDF, Word to HTML, Word to images. It also fixes some known issues such as the generated file cannot be opened after converting the Word file to PDF. More details are listed below.

Here is a list of changes made in this release

Category ID Description
Bug SPIREDOC-6464
SPIREDOC-7067
Fixes the issue that the application threw "IndexOutOfBoundsException" when updating the table of content of the Word document.
Bug SPIREDOC-6921
SPIREDOC-7107
Fixes the issue that the generated file has extra blank pages after converting the Word file to PDF.
Bug SPIREDOC-6954 Fixes the issue that the generated file cannot be opened after converting the Word file to PDF.
Bug SPIREDOC-6980 Fixes the issue that the generated file has duplicate images after converting the Word file to PDF.
Bug SPIREDOC-7026 Fixes the issue that the font of the generated file was changed after converting the Word file to HTML.
Bug SPIREDOC-7041 Fixes the issue that the location of the table in the generated file has changed after converting the Word file to PDF.
Bug SPIREDOC-7045 Fixes the issue that the value of the list in the generated file was incorrect after converting the Word file to HTML.
Bug SPIREDOC-7047 Fixes the issue that the application was out of memory when updating the table of content of the Word document.
Bug SPIREDOC-7064 Fixes the issue that the application threw "NullPointerException" when comparing the Word files.
Bug SPIREDOC-7099 Fixes the issue that the menclose label displayed incorrectly in the generated file after adding ML math code to the Word file.
Bug SPIREDOC-7101 Fixes the issue that the application took long time when updating the table of content of the Word document.
Bug SPIREDOC-7106
SPIREDOC-7156
SPIREDOC-7159
Fixes the issue that the location of the content in the generated file was incorrect after converting the Word file to PDF.
Bug SPIREDOC-7110 Fixes the issue that the frame of the image in the generated file was disappeared after converting the Word file to PDF.
Bug SPIREDOC-7119 Fixes the issue that the generated file has an extra content after accepting the track changes of the Word file.
Bug SPIREDOC-7125 Fixes the issue that the tap size of the table in the generated file was changed after combining the Word files.
Bug SPIREDOC-7137 Fixes the issue that the content of the generated file is different with the original file after converting the Word file to Images.
Bug SPIREDOC-7149 Fixes the issue that the application threw "NullPointerException" when converting the Word file to HTML.
Bug SPIREDOC-7151 Fixes the issue that the application threw "Item has already been added" when loading the Word file.
Bug SPIREDOC-7160 Fixes the issue that the content of the page number of the footer in the generated file was incorrect after converting the Word file to PDF.
Bug SPIREDOC-7171 Optimizes the speed of converting the Word file to PDF.
Bug SPIREDOC-7176 Fixes the issue that the value of the list in the generated file was incorrect after converting a Doc format Word file to Docx format.
Bug SPIREDOC-7178 Fixes the issue that the result was incorrect after splitting the table cell of the Word file.
Bug SPIREDOC-7184 Fixes the issue that the effect of the generated file was different with the MS Word generated after updating the table of content of the Word file.
Bug SPIREDOC-7206 Fixes the issue that the content of the math formula was incorrect when recognizing formulas in Word.
Click the link to download Spire.Doc for Java 5.1.9:
Tuesday, 11 January 2022 09:30

Java: Export Table Data from PDF to Excel

Tables are commonly seen in PDF invoices and financial reports. You may encounter the situation where you need to export PDF table data into Excel, so that you can analyze the data using the tools provided by MS Excel. This article explains how to extract tables from a PDF page and export them as individual Excel worksheets using Spire.Office for Java.

Install Spire.Office for Java

The scenario actually uses Spire.PDF for Java for extracting tables from PDF, and Spire.XLS for Java for generating Excel files. In order to use them in the same project, you’ll need to add the Spire.Office.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.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.office</artifactId>
        <version>4.12.2</version>
    </dependency>
</dependencies>

Export Table Data from PDF to Excel

The following are the main steps to extract all tables from a certain page and save each of them as an individual worksheet in an Excel document.

  • Load a sample PDF document while initializing the PdfDocument object.
  • Create a PdfTableExtractor object, and call extactTable(int pageIndex) method under it to extract all tables in the first page.
  • Create a Workbook instance.
  • Loop through the tables in the PdfTable[] array, and get the specific one by its index.
  • Add a worksheet to the workbook using Workbook.getWorksheets.add() method.
  • Loop through the cells in the PDF table, and get the value of a specific cell using PdfTable.getText(int rowIndex, int columnIndex) method. Then insert the value to the worksheet using Worksheet.get(int row, int column).setText(String string) method.
  • Save the workbook to an Excel document using Workbook.saveToFile() method.
  • Java
import com.spire.pdf.PdfDocument;
import com.spire.pdf.utilities.PdfTable;
import com.spire.pdf.utilities.PdfTableExtractor;
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class ExtractTableDataAndSaveInExcel {

    public static void main(String[] args) {

        //Load a sample PDF document
        PdfDocument pdf = new PdfDocument("C:\\Users\\Administrator\\Desktop\\Tables.pdf");

        //Create a PdfTableExtractor instance
        PdfTableExtractor extractor = new PdfTableExtractor(pdf);
        
        //Extract tables from the first page
        PdfTable[] pdfTables  = extractor.extractTable(0);

        //Create a Workbook object,
        Workbook wb = new Workbook();

        //Remove default worksheets
        wb.getWorksheets().clear();

        //If any tables are found
        if (pdfTables != null && pdfTables.length > 0) {

            //Loop through the tables
            for (int tableNum = 0; tableNum < pdfTables.length; tableNum++) {

                //Add a worksheet to workbook
                String sheetName = String.format("Table - %d", tableNum + 1);
                Worksheet sheet = wb.getWorksheets().add(sheetName);

                //Loop through the rows in the current table
                for (int rowNum = 0; rowNum < pdfTables[tableNum].getRowCount(); rowNum++) {

                    //Loop through the columns in the current table
                    for (int colNum = 0; colNum < pdfTables[tableNum].getColumnCount(); colNum++) {

                        //Extract data from the current table cell
                        String text = pdfTables[tableNum].getText(rowNum, colNum);

                        //Insert data into a specific cell
                        sheet.get(rowNum + 1, colNum + 1).setText(text);

                    }
                }

                //Auto fit column width
                for (int sheetColNum = 0; sheetColNum < sheet.getColumns().length; sheetColNum++) {
                    sheet.autoFitColumn(sheetColNum + 1);
                }
            }
        }

        //Save the workbook to an Excel file
        wb.saveToFile("output/ExportTableToExcel.xlsx", ExcelVersion.Version2016);
    }
}

Java: Export Table Data from PDF to Excel

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.

Office Open XML (also referred to as OOXML) is a zipped, XML-based format for Excel, Word and Presentation documents. Sometimes, you may need to convert an Excel file to Office Open XML in order to make it readable on various applications and platforms. Likewise, you might also want to convert Office Open XML to Excel for data calculations. In this article, you will learn how to Convert Excel to Office Open XML and vice versa in Java using Spire.XLS for Java library.

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.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.xls</artifactId>
        <version>4.12.2</version>
    </dependency>
</dependencies>

Convert Excel to Office Open XML in Java

The following are the steps to convert an Excel file to Office Open XML:

  • Create an instance of Workbook class.
  • Load an Excel file using Workbook.loadFromFile() method.
  • Call Workbook.saveAsXml() method to save the Excel file as Office Open XML.
  • Java
import com.spire.xls.Workbook;

public class ExcelToOpenXML {
    public static void main(String []args){
        //Create a Workbook instance
        Workbook workbook = new Workbook();
        //Load an Excel file
        workbook.loadFromFile("Sample.xlsx");

        //Save as Office Open XML file format
        workbook.saveAsXml("ToXML.xml");
    }
}

Java: Convert Excel to Office Open XML and Vice Versa

Convert Office Open XML to Excel in Java

The following are the steps to convert an Office Open XML file to Excel:

  • Create an instance of Workbook class.
  • Load an Office Open XML file using Workbook.loadFromXml() file.
  • Call Workbook.saveToFile() method to save the Office Open XML file as Excel.
  • Java
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;

public class OpenXmlToExcel {
    public static void main(String []args){
        //Create an instance of Workbook class
        Workbook workbook = new Workbook();
        //Load an Office Open XML file
        workbook.loadFromXml("ToXML.xml");

        //Save as Excel XLSX file format
        workbook.saveToFile("ToExcel.xlsx", ExcelVersion.Version2016);
    }
}

Java: Convert Excel to Office Open XML and Vice Versa

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.

We are glad to announce the release of Spire.Presentation for Java 5.1.0. This version fixes the issue that the application threw "NullPointerException" when loading a PowerPoint document. More details are listed below.

Here is a list of changes made in this release

Category ID Description
Bug SPIREPPT-1798 Fixes the issue that the application threw "NullPointerException" when loading a PowerPoint document.
Click the link to download Spire.Presentation for Java 5.1.0.
Page 2 of 148