Monday, 25 May 2020 07:11

Hide Gridlines in Excel Chart in Java

This article demonstrates how to hide gridlines in an Excel chart using Spire.XLS for Java.

import com.spire.xls.*;

public class HideGridlinesInChart {

    public static void main(String[] args) {

        //Create a Workbook object
        Workbook workbook = new Workbook();

        //Load an Excel file that contains data for creating chart
        workbook.loadFromFile("C:\\Users\\Administrator\\Desktop\\data.xlsx");

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

        //Add a column chart
        Chart chart = sheet.getCharts().add(ExcelChartType.ColumnClustered);
        chart.setChartTitle("Column Chart");

        //Set the chart data range
        chart.setDataRange(sheet.getCellRange("A1:C5"));
        chart.setSeriesDataFromRange(false);

        //Set the chart position
        chart.setLeftColumn(1);
        chart.setTopRow(6);
        chart.setRightColumn(8);
        chart.setBottomRow(19);

        //Hide the grid lines of chart
        chart.getPrimaryValueAxis().hasMajorGridLines(false);

        //Save the document
        workbook.saveToFile("HideGridlines.xlsx", ExcelVersion.Version2016);
    }
}

Hide Gridlines in Excel Chart in Java

This article demonstrrates how to accept or reject all tracked changes in a Word document using Spire.XLS for Java.

Sample Document

Accept or Reject Tracked Changes in Word in Java

import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class AcceptOrRejectChanges {

    public static void main(String[] args) {

        //Create a Document object
        Document doc = new Document();
        
        //Load the sample Word file
        doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.docx");

        //Accept all changes in the entire document
        doc.acceptChanges();
        
        ////Reject all changes in the entire document
        //doc.rejectChanges();
        
        //Save the document
        doc.saveToFile("AcceptAllChanges.docx", FileFormat.Docx);
    }
}

Output

Accept or Reject Tracked Changes in Word in Java

Tuesday, 19 May 2020 08:10

Convert SVG to PDF in C#/VB.NET

With Spire.PDF for .NET, we could save PDF to SVG easily. Starts from Spire.PDF V 6.5.6, it supports to convert SVG image to PDF. This article will demonstrate how to add a SVG image to PDF file and convert SVG to PDF.

Convert SVG to PDF

Spire.PDF offers a method of doc.LoadFromSvg() to load the SVG directly and doc.SaveToFile()method to save to PDF file.

Firstly, view the Sample SVG image:

Convert SVG to PDF in C#/VB.NET

C#
using Spire.Pdf;

namespace SVGtoPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromSvg("Sample.svg");

            doc.SaveToFile("Result.pdf", FileFormat.PDF);  

        }
    }
}
VB.NET
Imports Spire.Pdf

Namespace SVGtoPDF
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            Dim doc As PdfDocument = New PdfDocument
            doc.LoadFromSvg("Sample.svg")
            doc.SaveToFile("Result.pdf", FileFormat.PDF)
        End Sub
    End Class
End Namespace

Effective screenshot after converting SVG to PDF:

Convert SVG to PDF in C#/VB.NET

Add SVG image to PDF file

Besides convert the SVG directly to PDF, it also supports to add an existing SVG image to PDF file. It also supports to set the position and size of the SVG image after adding it to PDF. Please check the steps as below:

C#
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

namespace AddSVGImagetoPDF
{
    class Program
    {
        static void Main(string[] args)
        {

            PdfDocument doc1 = new PdfDocument();
            doc1.LoadFromSvg("Sample.svg");

            PdfDocument doc2 = new PdfDocument();
            doc2.LoadFromFile("Sample2.pdf");

            PdfTemplate template = doc1.Pages[0].CreateTemplate();


            //template.Draw(doc2.Pages[0].Canvas, new PointF());

            //set the position and size of SVG image
            doc2.Pages[0].Canvas.DrawTemplate(doc1.Pages[0].CreateTemplate(), new PointF(80, 80), new SizeF(300, 300));

            doc2.SaveToFile("Result0.pdf", FileFormat.PDF);   


        }
    }
}
VB.NET
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports System.Drawing

Namespace AddSVGImagetoPDF
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            Dim doc1 As PdfDocument = New PdfDocument
            doc1.LoadFromSvg("Sample.svg")
            Dim doc2 As PdfDocument = New PdfDocument
            doc2.LoadFromFile("Sample2.pdf")
            Dim template As PdfTemplate = doc1.Pages(0).CreateTemplate
            'template.Draw(doc2.Pages[0].Canvas, new PointF());
            'set the posion and size of SVG image
            doc2.Pages(0).Canvas.DrawTemplate(doc1.Pages(0).CreateTemplate, New PointF(80, 80), New SizeF(300, 300))
            doc2.SaveToFile("Result0.pdf", FileFormat.PDF)
        End Sub
    End Class
End Namespace

Effective screenshot after adding a SVG image to PDF file:

Convert SVG to PDF in C#/VB.NET

Tuesday, 19 May 2020 01:13

Create a PDF Portfolio in C#

A PDF Portfolio allows us to put multiple types of files (for example, text documents, email messages, spreadsheets and PowerPoint presentations) together into a master PDF file. The files in a PDF Portfolio can retain their individual identities. We can open, read, edit, and format each component file independently of the other component files.

Spire.PDF for .NET supports creating a PDF Portfolio, adding files and folders to the PDF Portfolio. The following example demonstrates how to create a PDF Portfolio and add files to it using Spire.PDF for .NET.

using System;
using Spire.Pdf;

namespace CreatePDFPortfolio
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] files = new String[] { "Instruction.pdf", "Sales Report.docx", "Sample.xlsx" };
            //Create a PdfDocument instance
            using (PdfDocument doc = new PdfDocument())
            {
                //Create a PDF Portfolio and add files to it
                for (int i = 0; i < files.Length; i++)
                {
                    doc.Collection.AddFile(files[i]);
                    
                }
                //Save the result file
                doc.SaveToFile("PortfolioWithFiles.pdf", FileFormat.PDF);
                doc.Dispose();
            }
        }
    }
}

Create a PDF Portfolio in C#

The following example shows how to create a PDF Portfolio and add folders to it using Spire.PDF for .NET.

using System;
using Spire.Pdf;
using Spire.Pdf.Collections;

namespace CreatePDFPortfolio
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] files = new String[] { "Instruction.pdf", "Sales Report.docx", "Sample.xlsx" };
            //Create a PdfDocument instance
            using (PdfDocument doc = new PdfDocument())
            {
                //Create a PDF Portifolio, add folders to it and add files to the folders
                for (int i = 0; i < files.Length; i++)
                {                                       
                    PdfFolder folder = doc.Collection.Folders.CreateSubfolder("Folder" + i);
                    folder.AddFile(files[i]);
                }
                //Save the result file
                doc.SaveToFile("PortfolioWithFolders.pdf", FileFormat.PDF);
                doc.Dispose();
            }
        }
    }
}

Create a PDF Portfolio in C#

This article demonstrates how to extract text from textbox within a worksheet using Spire.XLS for Java.

Sample Document

Extract Text from Textbox in Excel in Java

import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
import com.spire.xls.core.spreadsheet.shapes.XlsTextBoxShape;

public class ExtractTextFromTextbox {

    public static void main(String[] args) {

        //Create a Workbook instance
        Workbook workbook = new Workbook();

        //Load a sample Excel file
        workbook.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.xlsx");

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

        //Get the first textbox
        XlsTextBoxShape shape = (XlsTextBoxShape)sheet.getTextBoxes().get(0);

        //Get the text inside the textbox
        String text = shape.getText();
        System.out.print(text);
    }
}

Output

Extract Text from Textbox in Excel in Java

Tuesday, 12 May 2020 08:32

Hide or Show Comments in Excel in Java

This article demonstrates how to hide or show comments in an Excel file using Spire.XLS for Java.

The sample Excel file:

Hide or Show Comments in Excel in Java

import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

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

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

        //Hide the first and the second comments
        sheet.getComments().get(0).isVisible(false);
        sheet.getComments().get(1).isVisible(false);

        //Show the third comment
        sheet.getComments().get(2).isVisible(true);

        //Save the result file
        workbook.saveToFile("HideOrShowComment.xlsx", ExcelVersion.Version2013);
    }
}

The output Excel file:

Hide or Show Comments in Excel in Java

Tuesday, 12 May 2020 08:19

Convert HTML to Excel in C#/VB.NET

With Spire.XLS, we could save Excel to HTML easily. Starts from Spire.XLS V10.4.9, Spire.XLS starts to support saving HTML to Excel in C#/VB.NET. This article will show you how to convert HTML to Excel with the help of Spire.XLS.

Firstly, view the sample HTML file:

Convert HTML to Excel in C#/VB.NET

C# of converting HTML to Excel:

using Spire.Xls;

namespace HTML_to_Excel
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load the sample document 
            Workbook workbook = new Workbook();
            workbook.LoadFromHtml("Sample.html");

            //AutoFit rows
            Worksheet sheet = workbook.Worksheets[0];
            sheet.AllocatedRange.AutoFitRows();

            //Save the document to file
            workbook.SaveToFile("Result.xlsx",FileFormat.Version2010);
            
        }
    }
}
VB.NET
Imports Spire.Xls

Namespace HTML_to_Excel
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            'Load the sample document 
            Dim workbook As Workbook = New Workbook
            workbook.LoadFromHtml("Sample.html")
            'AutoFit rows
            Dim sheet As Worksheet = workbook.Worksheets(0)
            sheet.AllocatedRange.AutoFitRows
            'Save the document to file
            workbook.SaveToFile("Result.xlsx", FileFormat.Version2010)
        End Sub
    End Class
End Namespace

Effective screenshot of converting HTML to Excel:

Convert HTML to Excel in C#/VB.NET

This article demonstrates how to set and get slide title in a PowerPoint document using Spire.Presentation for Java.

Set slide title

import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;

public class SetSlideTitle {
    public static void main(String[] args) throws Exception {
        //Create a Presentation instance
        Presentation ppt = new Presentation();
        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);
        
        //Set title for the slide
        slide.setTitle("Tile Text");
        
        //Save the result document
        ppt.saveToFile("SetTitle.pptx", FileFormat.PPTX_2013);
    }
}

Set and Get Slide Title in PowerPoint in Java

Get slide title

import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;

public class GetSlideTitle {
    public static void main(String[] args) throws Exception {
        //Create a Presentation instance
        Presentation ppt = new Presentation();
        //Load a PowerPoint document
        ppt.loadFromFile("SetTitle.pptx");

        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);

        //Print out the title of the slide
        String tile = slide.getTitle();
        System.out.println(tile);
    }
}

Set and Get Slide Title in PowerPoint in Java

Thursday, 07 May 2020 09:27

Hide or Show Gridlines in Excel in Java

This article demonstrates how to hide or show gridlines in a worksheet using Spire.XLS for Java.

import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class HideOrShowGridlines {

    public static void main(String[] args) {

        //Create a Workbook object
        Workbook workbook = new Workbook();

        //Load a sample Excel file
        workbook.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.xlsx");

        //Get the fisrt worksheet
        Worksheet worksheet = workbook.getWorksheets().get(0);

        //Hide gridlines
        worksheet.setGridLinesVisible(false);

        ////Show gridlines
        //worksheet.setGridLinesVisible(true);

        //Save the document
        workbook.saveToFile("HideGridlines.xlsx", ExcelVersion.Version2016);
    }
}

Hide Gridlines

Hide or Show Gridlines in Excel in Java

This article will introduce how to extract text from SmartArt in PowerPoint in Java applications.

Firstly view the sample document:

Java extract text from SmartArt in PowerPoint

import com.spire.presentation.Presentation;
import com.spire.presentation.diagrams.ISmartArt;
import java.io.*;

public class extractTextFromSmartArt {
    public static void main(String[] args) throws Exception {
        Presentation presentation = new Presentation();
        presentation.loadFromFile("Sample.pptx");

        //Create a new TXT File
        String result = "output/extractTextFromSmartArt.txt";
        File file=new File(result);
        if(file.exists()){
            file.delete();
        }
        file.createNewFile();
        FileWriter fw =new FileWriter(file,true);
        BufferedWriter bw =new BufferedWriter(fw);

        bw.write("Below is extracted text from SmartArt:" + "\r\n");

        //Traverse through all the slides of the PPT file and find the SmartArt shapes.
        for (int i = 0; i < presentation.getSlides().getCount(); i++)
        {
            for (int j = 0; j < presentation.getSlides().get(i).getShapes().getCount(); j++)
            {
                if (presentation.getSlides().get(i).getShapes().get(j) instanceof ISmartArt)
                {
                    ISmartArt smartArt = (ISmartArt)presentation.getSlides().get(i).getShapes().get(j);

                    //Extract text from SmartArt and append to the StringBuilder object.
                    for (int k = 0; k < smartArt.getNodes().getCount(); k++)
                    {
                        bw.write(smartArt.getNodes().get(k).getTextFrame().getText() + "\r\n");
                    }
                }
            }
        }
        bw.flush();
        bw.close();
        fw.close();

    }
}

Effective screenshot of the extracting Text from SmartArt:

Java extract text from SmartArt in PowerPoint

Page 10 of 130