This article demonstrates how to add and delete digital signature in an Excel file using Spire.XLS for .NET.

Add digital signature

C#
using System;
using System.Security.Cryptography.X509Certificates;
using Spire.Xls;
using Spire.Xls.Core.MergeSpreadsheet.Interfaces;

namespace Add_Digital_Signature
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook instance
            Workbook workbook = new Workbook();
            //Load an Excel file
            workbook.LoadFromFile("Sample.xlsx");

            //Add digital signature to the file
            X509Certificate2 cert = new X509Certificate2("gary.pfx", "e-iceblue");
            DateTime certtime = new DateTime(2020, 7, 1, 7, 10, 36);
            IDigitalSignatures signature = workbook.AddDigitalSignature(cert, "e-iceblue", certtime);
            
            //Save the result file
            workbook.SaveToFile("AddDigitalSignature.xlsx", FileFormat.Version2013);
        }
    }
}
VB.NET
Imports System
Imports System.Security.Cryptography.X509Certificates
Imports Spire.Xls
Imports Spire.Xls.Core.MergeSpreadsheet.Interfaces

Namespace Add_Digital_Signature
    Class Program
        Private Shared Sub Main(ByVal args As String())
            Dim workbook As Workbook = New Workbook()
            workbook.LoadFromFile("Sample.xlsx")
            Dim cert As X509Certificate2 = New X509Certificate2("gary.pfx", "e-iceblue")
            Dim certtime As DateTime = New DateTime(2020, 7, 1, 7, 10, 36)
            Dim signature As IDigitalSignatures = workbook.AddDigitalSignature(cert, "e-iceblue", certtime)
            workbook.SaveToFile("AddDigitalSignature.xlsx", FileFormat.Version2013)
        End Sub
    End Class
End Namespace

 

Add and Delete Digital Signature in Excel in C#, VB.NET

Delete digital signature

C#
using Spire.Xls;

namespace Delete_Digital_Signature
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook instance
            Workbook workbook = new Workbook();
            //Load an Excel file
            workbook.LoadFromFile("AddDigitalSignature.xlsx");

            //Remove all the digital signatures in the file
            workbook.RemoveAllDigitalSignatures();

            //Save the result file
            workbook.SaveToFile("RemoveDigitalSignature.xlsx", FileFormat.Version2013);
        }
    }
}
VB.NET
Imports Spire.Xls

Namespace Delete_Digital_Signature
    Class Program
        Private Shared Sub Main(ByVal args As String())
            Dim workbook As Workbook = New Workbook()
            workbook.LoadFromFile("AddDigitalSignature.xlsx")
            workbook.RemoveAllDigitalSignatures()
            workbook.SaveToFile("RemoveDigitalSignature.xlsx", FileFormat.Version2013)
        End Sub
    End Class
End Namespace

The output Excel file after deleting digital signature:

Add and Delete Digital Signature in Excel in C#, VB.NET

This article demonstrates how to set spacing between paragraphs and how to set line spacing within a paragraph using Spire.Doc for Java.

Set Paragraph Spacing

import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.Section;
import com.spire.doc.documents.Paragraph;

public class SetParagraphSpacing {

    public static void main(String[] args) {

        //Create a Document instance
        Document doc = new Document();

        //Add a section
        Section section = doc.addSection();

        //Add a paragraph
        Paragraph para = section.addParagraph();
        para.appendText("Spire.Doc for Java is a professional Java Word API that enables Java applications to " +
                "manipulate Word documents without using Microsoft Office.");

        //Set paragraph after spacing
        para.getFormat().setAfterSpacing(20f);

        //Add another paragraph
        para = section.addParagraph();
        para.appendText("A plenty of Word document processing tasks can be performed by Spire.Doc for Java, "+
                "such as creating, comparing, reading, editing, converting and printing Word documents, "+
                "inserting image, adding header and footer, creating table and adding form field.");
        
        //Save the document
        doc.saveToFile("output/SetParagraphSpacing.docx", FileFormat.Docx_2013);
    }
}

Set Paragraph Spacing and Line Spacing in Word in Java

Set Line Spacing

import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.Section;
import com.spire.doc.documents.Paragraph;

public class SetLineSpacing {

    public static void main(String[] args) {

        //Create a Document instance
        Document doc = new Document();

        //Add a section
        Section section = doc.addSection();

        //Add a paragraph
        Paragraph para = section.addParagraph();
        para.appendText("Spire.Doc for Java is a professional Java Word API that enables Java applications to " +
                "manipulate Word documents without using Microsoft Office. A plenty of Word document " +
                "processing tasks can be performed by Spire.Doc for Java, such as creating, comparing, " +
                "reading, editing, converting and printing Word documents, inserting image, adding header " +
                "and footer, creating table and adding form field.");

        //Set line spacing
        para.getFormat().setLineSpacing(30f);

        //Save the document
        doc.saveToFile("SetLineSpacing.docx", FileFormat.Docx_2013);
    }
}

Set Paragraph Spacing and Line Spacing in Word in Java

Tuesday, 03 November 2020 08:31

Remove Header and Footer in Word in Java

There can be 3 types of headers and footers in a Word document, i.e. on first page, on odd pages and on even pages. This article demonstrates how to remove all the headers and footers on first page, on odd pages and on even pages in a section of a Word document using Spire.Doc for Java.

Remove Header

import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.HeaderFooter;
import com.spire.doc.Section;
import com.spire.doc.documents.HeaderFooterType;

public class RemoveHeader {
    public static void main(String[] args){
        //Create a Document instance
        Document doc = new Document();
        //Load a sample Word document
        doc.loadFromFile("Sample.docx");

        //Get the first section
        Section section = doc.getSections().get(0);

        //Remove the header on the first page
        HeaderFooter header = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.Header_First_Page);
        if (header != null)
            header.getChildObjects().clear();
        
        //Remove the header on the odd pages
        header = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.Header_Odd);
        if (header != null)
            header.getChildObjects().clear();
        
        //Remove the header on the even pages
        header = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.Header_Even);
        if (header != null)
            header.getChildObjects().clear();

        //Save the result document
        doc.saveToFile("RemoveHeader.docx", FileFormat.Docx_2013);
    }
}

Remove Footer

import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.HeaderFooter;
import com.spire.doc.Section;
import com.spire.doc.documents.HeaderFooterType;

public class RemoveFooter {
    public static void main(String[] args){
        //Create a Document instance
        Document doc = new Document();
        //Load a sample Word document
        doc.loadFromFile("Sample.docx");

        //Get the first section
        Section section = doc.getSections().get(0);

        //Remove footer on the first page
        HeaderFooter footer = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.Footer_First_Page);
        if (footer != null)
            footer.getChildObjects().clear();

        //Remove footer on the odd pages
        footer = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.Footer_Odd);
        if (footer != null)
            footer.getChildObjects().clear();

        //Remove footer on the even pages
        footer = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.Footer_Even);
        if (footer != null)
            footer.getChildObjects().clear();

        //Save the result document
        doc.saveToFile("RemoveFooter.docx", FileFormat.Docx_2013);
    }
}
Tuesday, 03 November 2020 06:52

Create Scatter Chart in Excel in Java

This article demonstrates how to create a scatter chart and add a trendline to it in an Excel document by using Spire.XLS for Java.

import com.spire.xls.*;
import com.spire.xls.core.IChartTrendLine;

import java.awt.*;

public class ScatterChart {
    public static void main(String[] args) {

        //Create a a Workbook object and get the first worksheet
        Workbook workbook = new Workbook();
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Rename the first worksheet and set the column width
        sheet.getCellRange("A1:B1").setColumnWidth(22f);;
        sheet.setName("Scatter Chart");

        //Insert data
        sheet.getCellRange("A1").setValue("Advertising Expenditure");
        sheet.getCellRange("A2").setValue("10429");
        sheet.getCellRange("A3").setValue("95365");
        sheet.getCellRange("A4").setValue("24085");
        sheet.getCellRange("A5").setValue("109154");
        sheet.getCellRange("A6").setValue("34006");
        sheet.getCellRange("A7").setValue("84687");
        sheet.getCellRange("A8").setValue("17560");
        sheet.getCellRange("A9").setValue ("61408");
        sheet.getCellRange("A10").setValue ("29402");

        sheet.getCellRange("B1").setValue("Sales Revenue");
        sheet.getCellRange("B2").setValue ("42519");
        sheet.getCellRange("B3").setValue("184357");
        sheet.getCellRange("B4").setValue ("38491");
        sheet.getCellRange("B5").setValue ("214956");
        sheet.getCellRange("B6").setValue ("75469");
        sheet.getCellRange("B7").setValue ("134735");
        sheet.getCellRange("B8").setValue("47935");
        sheet.getCellRange("B9").setValue ("151832");
        sheet.getCellRange("B10").setValue ("65424");

        //Set cell style
        sheet.getCellRange("A1:B1").getStyle().getFont().isBold(true);
        sheet.getCellRange("A1:B1").getStyle().setColor(Color.darkGray);
        sheet.getCellRange("A1:B1").getCellStyle().getExcelFont().setColor(Color.white);
        sheet.getCellRange("A1:B10").getStyle().setHorizontalAlignment(HorizontalAlignType.Center);
        sheet.getCellRange("A2:B10").getCellStyle().setNumberFormat("\"$\"#,##0") ;


        //Create a scatter chart and set its data range
        Chart chart = sheet.getCharts().add(ExcelChartType.ScatterMarkers);
        chart.setDataRange(sheet.getCellRange("B2:B10"));
        chart.setSeriesDataFromRange(false);

        //Set position of the chart.
        chart.setLeftColumn(4);
        chart.setTopRow(1);
        chart.setRightColumn(13);
        chart.setBottomRow(22);

        //Set chart title and series data label
        chart.setChartTitle("Advertising & Sales Relationship");
        chart.getChartTitleArea().isBold(true);
        chart.getChartTitleArea().setSize(12);
        chart.getSeries().get(0).setCategoryLabels(sheet.getCellRange("B2:B10"));
        chart.getSeries().get(0).setValues(sheet.getCellRange("A2:A10"));

        //Add a trendline
        IChartTrendLine trendLine = chart.getSeries().get(0).getTrendLines().add(TrendLineType.Exponential);
        trendLine.setName("Trendline");

        //Set title of  the x and y axis
        chart.getPrimaryValueAxis().setTitle("Advertising Expenditure ($)");
        chart.getPrimaryCategoryAxis().setTitle("Sales Revenue ($)");

        //Save the document
        workbook.saveToFile("ScatterChart.xlsx",ExcelVersion.Version2010);
        workbook.dispose();
    }
}

Create Scatter Chart in Excel in Java

Monday, 02 November 2020 08:42

Java add multiple headers to PDF

This article demonstrates how to use Spire. PDF for Java to add multiple headers to an existing PDF document in Java applications. The multiple headers on PDF means that different page has different header on the same PDF document.

import com.spire.pdf.*;
import com.spire.pdf.graphics.*;
import java.awt.*;
import java.awt.geom.*;

public class addDifferentHeaders {
    public static void main(String[] args) {
        String output = "output/addDifferentHeaders.pdf";

        //load the sample PDF document
        PdfDocument doc = new PdfDocument();
        doc.loadFromFile("Sample.pdf");
        String header1 = "Add header by Spire.PDF";
        String header2 = "Different header";

        //define style
        PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial",  Font.BOLD,12));
        PdfBrush brush= PdfBrushes.getBlue();
        Rectangle2D rect = new Rectangle2D.Float();
        Dimension2D dimension2D = new Dimension();
        dimension2D.setSize(doc.getPageSettings().getSize().getWidth(),50f);
        rect.setFrame(new Point2D.Float(0, 20), dimension2D);
        PdfStringFormat format=new PdfStringFormat();
        format.setAlignment(PdfTextAlignment.Center);
        //draw header string for the first page
        doc.getPages().get(0).getCanvas().drawString(header1,font,brush,rect,format);

        //draw header string for the second page
        format.setAlignment( PdfTextAlignment.Left);
        doc.getPages().get(1).getCanvas().drawString(header2, font, brush, rect, format);

        //save the document
        doc.saveToFile(output, FileFormat.PDF);
    }
}

Java add multiple headers to PDF

In addition to supporting adding background color to a whole Word document, Spire.Doc for Java can set background color for specified paragraph or text of a Word document. This article will demonstrate how to do it in Java programmatically.

Using the code

import com.spire.doc.*;
import com.spire.doc.documents.*;
import com.spire.doc.fields.*;
import java.awt.*;

public class SetParagraphShading {
    public static void main(String[] args) {
        //Load a Word document sample
        Document document = new Document();
        document.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.docx");

        //Get a specified paragraph from the sample
        Paragraph paragaph = document.getSections().get(0).getParagraphs().get(1);
        //Set background color for the paragraph.
        paragaph.getFormat().setBackColor(Color.yellow);

        //Get specified text from the sample
        paragaph = document.getSections().get(0).getParagraphs().get(6);
        TextSelection selection = paragaph.find("Spire.Doc for Java", true, false);
        //Set background color for the text 
        TextRange range = selection.getAsOneRange();
        range.getCharacterFormat().setTextBackgroundColor(Color.pink);

        //Saving the resulting document 
        document.saveToFile("output/setParagraphShading.docx", FileFormat.Docx_2013);
    }
}

Output

Java Set background color for specified paragraph or text of a Word document

Wednesday, 28 October 2020 02:44

Create a Line Chart in PowerPoint in Java

This article demonstrates how to create a line chart in a PowerPoint document using Spire.Presentation for Java.

import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideSizeType;
import com.spire.presentation.charts.ChartLegendPositionType;
import com.spire.presentation.charts.ChartType;
import com.spire.presentation.charts.IChart;

import java.awt.geom.Rectangle2D;

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

        //Create a Presentation object 
        Presentation presentation = new Presentation();
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //Insert a line chart 
        Rectangle2D.Double rect = new   Rectangle2D.Double(100, 50, 600, 430);
        IChart chart = presentation.getSlides().get(0).getShapes().appendChart(ChartType.LINE, rect);

        //Set chart title 
        chart.getChartTitle().getTextProperties().setText("Product Trends by Month");
        chart.getChartTitle().getTextProperties().isCentered(true);
        chart.getChartTitle().setHeight(30);
        chart.hasTitle(true);

        //Set axis title 
        chart.getPrimaryCategoryAxis().getTitle().getTextProperties().setText("Month");
        chart.getPrimaryCategoryAxis().hasTitle(true);
        chart.getPrimaryValueAxis().getTitle().getTextProperties().setText("Sales Volume");
        chart.getPrimaryValueAxis().hasTitle(true);

        //Write data to chart as chart data 
        chart.getChartData().get(0,0).setText("Month");
        chart.getChartData().get(1,0).setText("Jan");
        chart.getChartData().get(2,0).setText("Feb");
        chart.getChartData().get(3,0).setText("Mar");
        chart.getChartData().get(4,0).setText("Apr");
        chart.getChartData().get(5,0).setText("May");
        chart.getChartData().get(6,0).setText("Jun");

        chart.getChartData().get(0,1).setText("Desktops");
        chart.getChartData().get(1,1).setNumberValue(80);
        chart.getChartData().get(2,1).setNumberValue(45);
        chart.getChartData().get(3,1).setNumberValue(25);
        chart.getChartData().get(4,1).setNumberValue(20);
        chart.getChartData().get(5,1).setNumberValue(10);
        chart.getChartData().get(6,1).setNumberValue(5);

        chart.getChartData().get(0,2).setText("Laptops");
        chart.getChartData().get(1,2).setNumberValue(30);
        chart.getChartData().get(2,2).setNumberValue(25);
        chart.getChartData().get(3,2).setNumberValue(35);
        chart.getChartData().get(4,2).setNumberValue(50);
        chart.getChartData().get(5,2).setNumberValue(45);
        chart.getChartData().get(6,2).setNumberValue(55);

        chart.getChartData().get(0,3).setText("Tablets");
        chart.getChartData().get(1,3).setNumberValue(10);
        chart.getChartData().get(2,3).setNumberValue(15);
        chart.getChartData().get(3,3).setNumberValue(20);
        chart.getChartData().get(4,3).setNumberValue(35);
        chart.getChartData().get(5,3).setNumberValue(60);
        chart.getChartData().get(6,3).setNumberValue(95);

        //Set series labels 
        chart.getSeries().setSeriesLabel(chart.getChartData().get("B1", "D1"));

        //Set categories labels 
        chart.getCategories().setCategoryLabels(chart.getChartData().get("A2", "A7"));

        //Assign data to series values 
        chart.getSeries().get(0).setValues(chart.getChartData().get("B2", "B7"));
        chart.getSeries().get(1).setValues(chart.getChartData().get("C2", "C7"));
        chart.getSeries().get(2).setValues(chart.getChartData().get("D2", "D7"));

        //Display values in data labels 
        chart.getSeries().get(0).getDataLabels().setLabelValueVisible(true);
        chart.getSeries().get(1).getDataLabels().setLabelValueVisible(true);
        chart.getSeries().get(2).getDataLabels().setLabelValueVisible(true);

        //Set chart legend position 
        chart.getChartLegend().setPosition(ChartLegendPositionType.TOP);

        //Save to file 
        presentation.saveToFile("LineChart.pptx", FileFormat.PPTX_2013);
    }
}

Create a Line Chart in PowerPoint in Java

This article demonstrates how to use Spire.XLS for Java to split Excel text or numbers in one cell into multiple columns by delimiters. The delimiter characters could be Space ( ), Comma (,) Semicolon(;) etc.

import com.spire.xls.*;

public class splitDataIntoMultipleColumns {
    public static void main(String[] args) {
        //Load the sample document from file
        Workbook workbook = new Workbook();
        workbook.loadFromFile("Sample.xlsx");

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

        //Split data into separate columns by the delimiter characters of space.
        String[] splitText = null;
        String text = null;
        for (int i = 1; i < sheet.getLastRow(); i++)
        {
            text = sheet.getRange().get(i + 1, 1).getText();
            splitText = text.split(" ");
            for (int j = 0; j < splitText.length; j++)
            {
                sheet.getRange().get(i + 1, 1 + j + 1).setText(splitText[j]);
            }
        }
        //Save to file
        workbook.saveToFile("Result.xlsx", ExcelVersion.Version2013);
    }
}

Output:

Java split one cell contents into multiple columns in Excel

We have already introduced how to add animation effect to shape in PowerPoint, in this article, we will introduce how to add animation effect to paragraph in PowerPoint using Spire.Presentation for Java.

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.animation.*;

import java.awt.*;
import java.awt.geom.Rectangle2D;

public class AddAnimationOnParagraph {
    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);

        //Add a shape to the slide
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Double(150, 150, 450, 100));
        shape.getFill().setFillType(FillFormatType.SOLID);
        shape.getFill().getSolidColor().setColor(Color.gray);
        shape.getShapeStyle().getLineColor().setColor(Color.white);
        shape.appendTextFrame("This demo shows how to apply animation on paragraph in PPT document.");

        //Add animation effect to the first paragraph in the shape
        AnimationEffect animation = shape.getSlide().getTimeline().getMainSequence().addEffect(shape, AnimationEffectType.FLOAT);
        animation.setStartEndParagraphs(0, 0);

        //Save the result document
        ppt.saveToFile("AddAnimationOnPara.pptx", FileFormat.PPTX_2013);
        ppt.dispose();
    }
}

Output:

Add Animation Effect to Paragraph in PowerPoint in Java

Tuesday, 20 October 2020 07:03

Create Pivot Chart in Excel in Java

This article demonstrates how to create pivot chart in an Excel file in Java using Spire.XLS for Java.

The input Excel file:

Create Pivot Chart in Excel in Java

import com.spire.xls.*;
import com.spire.xls.core.IPivotTable;

public class CreatePivotChart {
    public static void main(String[] args) {
        //Load the Excel file
        Workbook workbook = new Workbook();
        workbook.loadFromFile("Sample.xlsx");

        //Get the first worksheet
        Worksheet sheet = workbook.getWorksheets().get(0);
        //get the first pivot table in the worksheet
        IPivotTable pivotTable = sheet.getPivotTables().get(0);

        //Add a clustered column chart based on the pivot table data to the second worksheet
        Chart chart = workbook.getWorksheets().get(1).getCharts().add(ExcelChartType.ColumnClustered, pivotTable);
        //Set chart position
        chart.setTopRow(2);
        chart.setBottomRow(15);
        //Set chart title
        chart.setChartTitle("Total");

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

Output:

Create Pivot Chart in Excel in Java

Page 2 of 129