page 189

Add table to slide

2017-08-23 05:53:43 Written by zaki zou

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;

namespace VSTO
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //Create empty presentation
            PowerPoint.Presentation ppt = this.Application.Presentations.Add();

            //Add a blank slide
            PowerPoint.Slide slide = ppt.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank);

            //Add table to slide
            PowerPoint.Shape shape = slide.Shapes.AddTable(6, 6, 0, 0, 800, 400);
            PowerPoint.Table table = shape.Table;

            //Loop the table to fill text
            for (int i = 1; i <= table.Rows.Count; i++)
            {
                for (int j = 1; j <= table.Columns.Count; j++)
                {                    
                    PowerPoint.TextFrame tf = table.Cell(i, j).Shape.TextFrame;
                    tf.TextRange.Text = "Row" + i.ToString() + "Col" + j.ToString();
                    tf.TextRange.ParagraphFormat.Alignment = PowerPoint.PpParagraphAlignment.ppAlignCenter;
                }
            }

            //Save the file
            ppt.SaveAs("Table.pptx");
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}

Add shapes to slide

2017-08-23 05:50:57 Written by zaki zou

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;

namespace VSTO
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //Create ppt document
            PowerPoint.Presentation ppt = Globals.ThisAddIn.Application.Presentations.Add();

            //Add a blank slide
            PowerPoint.Slide slide = ppt.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank);

            //Add rectangle shape
            slide.Shapes.AddShape(Office.MsoAutoShapeType.msoShapeRectangle, 50, 100, 100, 100);

            //Add arrow shape
            slide.Shapes.AddShape(Office.MsoAutoShapeType.msoShapeRightArrow, 200, 100, 100, 100);

            //Add triangle shape
            slide.Shapes.AddShape(Office.MsoAutoShapeType.msoShapeRightTriangle, 350, 100, 100, 100);

            //Save the file
            ppt.SaveAs("Shape.pptx");
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}

This article presents how to import Spire.Barcode.jar in Java application and create barcode image using the classes involved.

Import Spire.Barcode.jar file

Step 1: Download Spire.Barcode for Java from the following URL. Unzip the package into a directory, you'll get Spire.Barcode.jar and Spire.Common.jar in the lib folder.

Step 2: Create a Java project in Eclipse.

Step 3: Right click the project name, select "New" - "Folder" to create a folder named "Lib".

How to Create Barcode Using Spire.Barcode for Java

Step 4: Copy the Spire.Barcode.jar file and Spire.Common.jar file to this folder.

How to Create Barcode Using Spire.Barcode for Java

Step 5: Select all the jar files, then right click on one of them and select "Build Path" – "Add to Build Path".

How to Create Barcode Using Spire.Barcode for Java

Until now, Spire.Barcode.jar and Spire.Common.jar have been referenced in your Java project. Expand the specific jar file in the “Package Explore” pane, and you’ll be able to view the classes, methods, properties, etc. inside the jar file.

How to Create Barcode Using Spire.Barcode for Java

Using the code

Following code snippet provides an example of creating Code 128 barcode using Spire.Barcode for Java.

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import com.spire.barcode.BarCodeGenerator;
import com.spire.barcode.BarCodeType;
import com.spire.barcode.BarcodeSettings;

public class CODE_128 {

	public static void main(String[] args) throws IOException {
		
		//create an instance of BarcodeSetteings
        BarcodeSettings settings = new BarcodeSettings();
        //set barcode type
        settings.setType(BarCodeType.CODE_128);       
        //set barcode data
        settings.setData("123456789");
        //set the display text
        settings.setData2D("123456789");     
        //show text on bottom
        settings.setShowTextOnBottom(true);
        //set the border invisible
        settings.hasBorder(false);
        //create BarCodeGenerator object based on settings
        BarCodeGenerator barCodeGenerator = new BarCodeGenerator(settings);
        //generate image data and store in BufferedImage instance
        BufferedImage bufferedImage = barCodeGenerator.generateImage();
        //save to .png file format
        ImageIO.write(bufferedImage, "png", new File("CODE128.png"));
        System.out.println("Complete!");
	}
}

Output:

How to Create Barcode Using Spire.Barcode for Java

page 189