Close





 
Thursday, 20 October 2011 09:26

Word to EPUB for C#/VB.NET

The sample demonstrates how to export doc document to Epub file.

Published in Convertors
Monday, 08 August 2011 08:11

Spire.DataExport FAQ

1, How to add picture in spreadsheets ?

Q: How to add picture in spreadsheets ?
A: You can add pictures to result excel files with the following code:
CellImage img1 = new CellImage();
img1.Column = 1;
img1.PictureName = "demo";
img1.Row = 1;
cellExport1.Images.Add(img1);

CellPicture pic1= new CellPicture();
pic1.FileName = "C:\\demo.gif";
pic1.Name = "demo";
cellExport1.Pictures.Add(pic1);

cellExport1.SaveToFile();
Discuss here

 

2, Adding Titles

Q: The PDF export tool to me is a cool product. But I have couple of things that I am stuck and the help document is of no help at all. What I am trying to accomplish wit the PDF export is the following:
  • 1. How do I add Titles.
  • 2. How do I set the Page Numbers
  • 3. How do I add the Column Headers
  • 4. Page Size(Landscape or Portrait)
  • 5. Can I use Microsoft Application Blocks to get the data and then set the DataSource to a DataTable. Currently I am getting an error.
  •  

    Answers:
  • 1. How do I add Titles.
  • Add titles with the following code.
    pdfExport1.Header.Add("Spire.DataExport Headers");
    
  • 2. How do I set the Page Numbers
  • The Spire.DataExport produces page number automatically, You can't set page number in current version
  • 3. How do I add the Column Headers
  • The Spire.DataExport procedures column headers automatically, according your set datasource.
  • 4. Page Size(Landscape or Portrait)
  • Set page size with following code.
    pdfExport1.PDFOptions.PageOptions.Orientation = Spire.DataExport.Common.PageOrientation.Landscape;
    
  • 5. Can I use Microsoft Application Blocks to get the data and then set the DataSource to a DataTable. Currently I am getting an error.
  • If you set the Datasource to a DataTable , You need to set DataTable property to a datatable instance.

     

    Discuss here

     

    3, Restrict Date Format in Excel to 'dd\mm\yy'

    Q: While exporting to excel, Is there a way to restrict the format for date columns like 'dd\mm\yy'. And should not allow user to enter any other format on the excel.
    A: If you want to set data format on a column, You need to write code in GetDataParams event. Try to use the following example code:
    private void cellExport1_GetDataParams(object sender, Spire.DataExport.EventArgs.DataParamsEventArgs e)
    {
          if (e.Col == 1)
          {
                e.FormatText = "dd/MM/yy";
          }
    }
    
    Discuss here

     

    4, Export to PDF

    Q: Is there any possibility for export HTML document to PDF?
    A: Spire.DataExport can export data into html, excel, PDF document, etc, If you want export HTML document to PDF, you need to parse the html file and export data to PDF by Spire.DataExport.

     

    discuss here

     

    5, DBF column attributes

    Q: Looking at the product for possible purchase but have not been able to determine how the change/modify the attributes for a given column. That is we may have rows in which we have an output column that needs a different precison then the column next to it, or we have a string/text output column that has a length/size that is different then the source data.
    A: You can set ColumnsPrecision property value to change length and precision of column.
    Format: ColumnName=Length,Precision
    example: PartNo=8,2

     

    Discuss here

     

    6, export a datalist and a created chart image

    Q: One of my collegues gave me your dataexport module to integrate into a project. However i'm not seeing the possibillity to export a datalist and a created image. Is this possible?
    A: You can export datalist and a created image to excel file, for more detailed, please see example with installation.

     

    Discuss here

     

    7, export to xls: date not in date format

    Q: I'm doing an export to excel but my date is not displayed as a date. the correct date is in there but as a number. If i change the properties of the field, i will get the correct date. How can i fix this?
    Spire.DataExport.XLS.CellExport exp = new Spire.DataExport.XLS.CellExport();
    exp.DataFormats.CultureName = "nl-NL";
    exp.DataFormats.Float = "#,###,##0.00";
    [b]exp.DataFormats.DateTime = "dd-MM-yyyy";[/b]
    exp.DataFormats.Currency = "
    
    A: You need to add getParams event to CellExport component, Try to using following source code,
      private void cellExport1_GetDataParams(object sender, Spire.DataExport.EventArgs.DataParamsEventArgs e)
            {
                if (e.Col == 1)
                {
                    e.FormatText = "YYYY-MM-DD";
                }
            }
    
    Discuss here

     

    8, export to TXT Tab delimited

    Q: Is it possible to set the export to Tab Delimited?
    A: Please try to using following source code,
    txtExport1.CSVOption.Separator = "\tab";
    
    Discuss here

     

    9, solution for export with Ajax?

    Q: I'm getting quite used to working with your product, but one thing i'm still not capable of getting it done. I'm working on a project that is using a huge collection of AJAX and the scriptmanager. Since the scriptmanager doesn't really like the use of Respons, the SaveToHttpResponse is not working. Is there any other solution to create the effect that the user can download the file directly?
  • Is it possible to push the savetoHttpResponse to a popup and download the data from there?
  • Is it possible to save to stream and add the stream in my updatepanel so the download will be activated?
  • A: we recommend that you can iframe to link a aspx page, so you can use savetoreponse methd to download file.

     

    Discuss here

     

    10, Speed Issue

    Q: We are thinking about purchasing this control, however we are planning on performing large data dumps into csv files using this control, we are looking at around 100k rows from a data table. Has anyone used this DataExport tool to dump this large of data into a file and if so how was the speed issue, canyou give an approximate time of how long it took?
    A: This is related to the performance test machines, spent mainly in the implementation of the writing on the document

     

    Discuss here

     

    11, DataTable, DateTime format in DataExport to XLS

    Q: When I try to export a DataTable containing a DateTime field to Excel, it is shown as a number. The number is a correct value when shown as DateTime, but the cell format should be DateTime instead of Default. The DataTable correctly contains the column as DateTime.
    Here is a code snippet that reproduces the issue:
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = new SqlConnection(/* Insert some SQL Server connection string */);
    cmd.CommandText = "SELECT CAST('2010-01-01 0:00' AS DATETIME)";
    cmd.CommandType = CommandType.Text;
    SqlDataAdapter da = new SqlDataAdapter();
    da.SelectCommand = cmd;
    DataTable table = new DataTable();
    da.Fill(table);
    CellExport ce = new CellExport();
    ce.DataTable = table;
    ce.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
    ce.SaveToHttpResponse("test.xls", Response);
    
    The resulting Excel sheet contains the following data:
    Column1
    40179
    We consider purchasing Spire.DataExport, but I need to make this work... Please help.

     

    A: Please try to using following way, add GetDataParams event to Spire.DataExport.
       private void cellExport1_GetDataParams(object sender, Spire.DataExport.EventArgs.DataParamsEventArgs e)
       {
                    //e.sheet equals sheet index, e.col equals column index. 
       if    ((e.Sheet == 0) && (e.Col == 6))
       {
          e.FormatText = cellExport1.DataFormats.DateTime;
       }
    }
    
    Discuss here

     

    12, Convert Excel Files xlsx to pdf

    Q: is it possible with your Controls to convert a xlsx files to a pdf with only printing and 128bit security.
    A: Yes, you can convert Excel File to PDF just need to do two steps:
  • 1. use OleDbConnection to open the Excel file as a DataSource
  • 2. use Spire.DataExport to export the data to a PDF file.
  • The method following is a sample, the Excel file D:\temp\DatatableSample.xls is a test file in my computer.
    static void ConvertExcelToPDF()
    {
    OleDbConnection conn = new OleDbConnection();
    conn.ConnectionString
    = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\temp\DatatableSample.xls;Extended Properties=""Excel 8.0""";
    
    OleDbCommand command = new OleDbCommand();
    command.CommandText = "select * from [country$A1:E19]";
    command.Connection = conn;
    conn.Open();
    
    Spire.DataExport.PDF.PDFExport pdfExport1 = new Spire.DataExport.PDF.PDFExport();
    pdfExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
    pdfExport1.DataFormats.CultureName = "en-US";
    pdfExport1.DataFormats.Currency = "c";
    pdfExport1.DataFormats.DateTime = "yyyy-M-d H:mm";
    pdfExport1.DataFormats.Float = "g";
    pdfExport1.DataFormats.Integer = "g";
    pdfExport1.DataFormats.Time = "H:mm";
    pdfExport1.FileName = Guid.NewGuid() + ".pdf";
    pdfExport1.PDFOptions.DataFont.CustomFont = new System.Drawing.Font("Arial", 10F);
    pdfExport1.PDFOptions.FooterFont.CustomFont = new System.Drawing.Font("Arial", 10F);
    pdfExport1.PDFOptions.HeaderFont.CustomFont = new System.Drawing.Font("Arial", 10F);
    pdfExport1.PDFOptions.PageOptions.Format = Spire.DataExport.PDF.PageFormat.User;
    pdfExport1.PDFOptions.PageOptions.Height = 11.67;
    pdfExport1.PDFOptions.PageOptions.MarginBottom = 0.78;
    pdfExport1.PDFOptions.PageOptions.MarginLeft = 1.17;
    pdfExport1.PDFOptions.PageOptions.MarginRight = 0.57;
    pdfExport1.PDFOptions.PageOptions.MarginTop = 0.78;
    pdfExport1.PDFOptions.PageOptions.Width = 10.25;
    pdfExport1.PDFOptions.TitleFont.CustomFont = new System.Drawing.Font("Arial", 10F);
    pdfExport1.SQLCommand = command; 
    
    pdfExport1.SaveToFile();
    }
    
    But the Spire.DataExport does not currently support the other 2 requirements 'only printing and 128bit security'.

     

    Discuss here

     

    13, Export data from SQL to PDF

    Q: I want to export data to PDF from SQL. will free Spire.DataExport help me to do this?
    A: You can export data from database to PDF by using SQL command. You can refer to our demo here: http://www.e-iceblue.com/Knowledgebase/Spire.DataExport/Demos/Demo/Data-Export-PDF-for-C-VB.NET.html

     

    Discuss here

     

    14, PDF export, display problem

    Q: I'm using SPIRE EXPORT PDF as I want to generate from a datagridview (VB.NET 2010) a pdf ... I'm doing it through a mysql database as I didn't find a way to do it directly !
    so the code below saves the data written in the datagridview to the mysql bdd and then, it does an SQL to PDF with SPIRE export pdf
    'PrintDocument1.Print()
            Dim oleDbConnection1 = New MySqlConnection()
            
            Dim Server As String = "localhost"
            Dim Db As String = "PINF"
            Dim User As String = "root"
            Dim Pwd As String = ""
    
            oleDbConnection1.ConnectionString = "Server=" & Server & ";" _
            & "Uid=" & User & ";" _
            & "Pwd=" & Pwd & ";" _
            & " Database=" & Db & ";"
            
            Dim oleDbCommand1 As New MySqlCommand
            oleDbCommand1.Connection = oleDbConnection1
            oleDbConnection1.Open()
            For i = 0 To dgv.RowCount - 2
    
                oleDbCommand1.CommandText = "insert into ATL values ('" & dgv(0, i).Value & "', '" & dgv(1, i).Value & "', '" & dgv(2, i).Value & "', '" & dgv(3, i).Value & "', '" & dgv(4, i).Value & "', '" & dgv(5, i).Value & "', '" & dgv(6, i).Value & "')"
                oleDbCommand1.ExecuteScalar()
    
            Next
    
    
            Dim pdfExport1 As New Spire.DataExport.PDF.PDFExport()
            pdfExport1.PDFOptions.PageOptions.Orientation = 0
            pdfExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView
            pdfExport1.DataFormats.CultureName = "fr-FR"
            pdfExport1.DataFormats.Currency = "€"
            pdfExport1.DataFormats.DateTime = "d-M-yyyy"
            pdfExport1.DataFormats.Float = "g"
            pdfExport1.DataFormats.[Integer] = "g"
            pdfExport1.DataFormats.Time = "H:mm"
            pdfExport1.PDFOptions.HeaderFont.AllowCustomFont = True
            pdfExport1.PDFOptions.DataFont.AllowCustomFont = True
            pdfExport1.PDFOptions.FooterFont.AllowCustomFont = True
            pdfExport1.PDFOptions.TitleFont.AllowCustomFont = True
            pdfExport1.AutoFitColWidth = False
            pdfExport1.FileName = "sample1.pdf"
            pdfExport1.PDFOptions.DataFont.CustomFont = New System.Drawing.Font("Arial", 10.0F)
            pdfExport1.PDFOptions.FooterFont.CustomFont = New System.Drawing.Font("Arial", 10.0F)
            pdfExport1.PDFOptions.HeaderFont.CustomFont = New System.Drawing.Font("Arial", 10.0F)
            pdfExport1.PDFOptions.PageOptions.Format = Spire.DataExport.PDF.PageFormat.User
            pdfExport1.PDFOptions.PageOptions.Height = 11.67
            pdfExport1.PDFOptions.PageOptions.MarginBottom = 0.78
            pdfExport1.PDFOptions.PageOptions.MarginLeft = 1.17
            pdfExport1.PDFOptions.PageOptions.MarginRight = 0.57
            pdfExport1.PDFOptions.PageOptions.MarginTop = 0.78
            pdfExport1.PDFOptions.PageOptions.Width = 20 
            pdfExport1.PDFOptions.TitleFont.CustomFont = New System.Drawing.Font("Arial", 10.0F)
    
            pdfExport1.PDFOptions.ColSpacing = 0
            pdfExport1.PDFOptions.RowSpacing = 2
            pdfExport1.PDFOptions.GridLineWidth = 2
            oleDbCommand1.CommandText = "select * from ATL"
            pdfExport1.Header.Text = "ATL"
    
            'pdfExport1.PDFOptions.TitleFont.CustomFont = New System.Drawing.Font("Arial", 20.0F, FontStyle.Bold)
            pdfExport1.SQLCommand = oleDbCommand1
    
            pdfExport1.SaveToFile()
            oleDbConnection1.Close()
    
    But in the resulted PDF file .... the display is bad, I mean there are not all columns displayed ... and the columns are too spaced ! I don't know how to reduce the spacing of the columns .. if someone knows ..
    A: sorry, dataexport does not support custom column header at present. You could use Spire.Doc, by which you can export you data to a document and convert it to pdf please check here to get more information about spire.doc

     

    Discuss here

     

    15, Word Style Support

    Q: Is it possible to export data from database to Word with images and hyperlinks inserted with the free data export component?
    A: The free component can support several styles of Excel. Therefore, you can insert images and hyperlinks when exporting data to Word by using it. check it here

     

    Discuss here

     

    16, Export data SQL command

    Q: I want to use Spire.DataExport to control the data source with SQL command. How can I realize it?
    A: You can use the code:
    System.Data.OleDb.OleDbCommand oleDbcommand1 = new System.Data.OleDb.OleDbCommand(); 
    
    And write SQL command in oleDbcommand1.

     

    Discuss here

     

    17, Export Data to Excel and Generate Chart

    Q: I want to generate a chart according to my data after exporting data to Excel? Does the free Spire.DataExport support this?
    A: Yes, our free component supports it. Please check it on: http://www.e-iceblue.com/Knowledgebase/Spire.DataExport/Demos/Cell/Data-Export-Bar-Chart-for-C-VB.NET.html Download Data Export Component here

     

    18, Large Data Export

    Q: I learn that you can provide free data export component for downloading. I want to know if this component can export a large amount of data, for example, nearly 16000 columns.
    A: There is no column limitation of the free component. But, it will be limited by the file size. What's more, it supports only 65536 columns of Excel 2003.

     

    Discuss here

     

    19, DB connection issue

    Q: Yesterday, I used Spire.DataExport to export data from database, but I can't connect my database, here I give you my code:
    OleDbConnection oleDbConnection = new OleDbConnection(); 
    oleDbConnection.ConnectionString = this.txtCollectionString.Text;
    System.Data.OleDb.OleDbCommand oleDbCommand = new System.Data.OleDb.OleDbCommand();
    oleDbCommand.CommandText = this.txtCommandText.Text; 
    
    Can you help me?? Thank you in advance."
    A: I have realized your problem. After initializing the oleDbConnection and oleDbCommand, you should connect them with the following code:
    oleDbCommand.Connection = oleDbConnection;
    
    Discuss here

     

    20, Fill data table

    Q: When I fill my data table with the data source of the DataGridView, it appears an error. I give you the code:
    worksheet1.DataTable = this.dataGridView.DataSource;
    
    A: You don't convert the type. You should use the following code:
    worksheet1.DataTable = this.dataGridView.DataSource as DataTable;
    
    Discuss here

     

    21, Fill DataGridView with command

    Q: I want to assign the data source of the DataGridView with the oleDbCommand, but I failed. The code:
    dataGridView.DataSource = oleDbCommand;
    
    A: If you want to do so, you should use a data adapter, it like a intermediary of the command and DataGridView. You may use it with the following code:
    OleDbDataAdapter da = new OleDbDataAdapter(oleDbCommand); 
    DataTable dt = new DataTable();
    da.Fill(dt);
    dataGridView.DataSource = dt;
    
    Discuss here

     

    22, Worksheet export

    Q: When I use Spire.DataExport to export data from a database to a worksheet of XLS, it appears an error. I don't know why. Here is my code:
    Spire.DataExport.XLS.WorkSheet worksheet1 = new Spire.DataExport.XLS.WorkSheet(); 
    worksheet1.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
    worksheet1.DataTable = this.dataGridView.DataSource as DataTable;
    
    A: When I use Spire.DataExport to export data from a database to a worksheet of XLS, it appears an error. I don't know why. Here is my code:
    Spire.DataExport.XLS.WorkSheet worksheet1 = new Spire.DataExport.XLS.WorkSheet(); 
    worksheet1.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
    worksheet1.DataTable = this.dataGridView.DataSource as DataTable;
    
    Discuss here

     

    23, Open file

    Q: When I run my form, it will save to a file, but it can't open automatically. So I want it launched automatically. Can you help me??
    A: Of cource. You can use the following code to realize it:
    cellExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
    
    Discuss here

     

    24, Multiple Sheets (workbooks)

    Q: I am using the DataExport and trying to build an XLS (Excel) with multiple workbooks/sheets (some people may call it tabs). I followed the following example from e-iceblue's own website: http://www.e-iceblue.com/Knowledgebase/Spire.DataExport/Demos/Cell/net-data-export-cell-multiple-sheets-demo.html#twoj_fragment1-2
    The example works great, if you are going to add a maximum of 3 workbooks. I am in need of having around 6. If I try to add a fourth workbook, I do not get an error but I also don't get the fourth workbook. I was thinking I might have an error in the fourth workbook, so I comment out the 3rd workbook’s code and then I ran it again, the 4th workbook can now be seen (In workbook location #3)! Wow, so the fourth workbook has no errors! I uncommited the code for the 3rd workbook and bammm, the fourth workbook can’t be seen again. Only the first 3 workbooks can be seen.
    There must be some sort of limitations on how many workbooks can be added? :?:
    A: Sorry for any inconvenience caused by us. It looks like that your program worked on Spire.DataExport Community Edition. The maximum of 3 worksheets is a limitation. We also provide a Charged Edition of Spire.DataExport which can support up to 256 worksheets. You could get more information about the difference between them from the last table ,a href="http://www.e-iceblue.com/Introduce/data-export-for-net-intro.html">here. You could buy a license of Spire.DataExport Charged Edition from http://www.e-iceblue.com/Spire.DataExport.html.

     

    Discuss here

     

    25, SaveSpecificationToFile Exception

    Q: when i try to save a export specification to file, it throws an exception "ArgumentOutOfRangeException". My code:
    Dim txtExport1 As New Spire.DataExport.TXT.TXTExport()
    
    txtExport1.DataSource = Spire.DataExport.Common.ExportSource.DataTable
    txtExport1.DataEncoding = Spire.DataExport.Common.EncodingType.ASCII
    txtExport1.ExportType = Spire.DataExport.TXT.TextExportType.CSV
    
    txtExport1.SaveSpecificationToFile("C:\test.txt")
    
    A: You can use this method.
    txtExport1.SaveToFile("C:\test.txt");
    
    The SaveSpecificationToFile() method can not work.

     

    Discuss here

     

    26, Error During Install

     

    27, Unreadable content Spire DataExport XLS

    Q: i opened the export file and excel show popup "Excel found unreadable content in 'xxxxxxx.xls'. Do you want to recover....."
    why that popup show and how to hide it ?
    A: We need your code and files. Please upload to us, so that we can reproduce the problem.

     

    Discuss here
    Published in Program Guide
    Tuesday, 12 July 2011 06:48

    Doc MailMerge Silverlight

    The sample demonstrates how to work with MailMerge in Silverlight via Spire.Doc.

    Download template doc file.

    Download merged result file.

    Published in MailMerge
    Spire PDF Converter enables users to encrypt PDF documents when converting to PDF. Users can set own password and user password. Also, users can set individual security permissions, for example, print, edit and so on.

    How to Encrypt PDF Document

    1. Register to Download Spire PDF Converter (Free Beta Version) and Run it.

    2. Choose a Document.

    Click Add files, select the document you want to convert and encrypt.

    3. Encrypt PDF Document

    Click Encryption button and then set password and permissions.
    Set Own Password
    Set User Password
    Permissions

    4. Convert Document

    Click Encryption to confirm. Save the document in a specific path by clicking browse. Then, Click Convert.
    Now, the document has been converted to PDF and encrypted.
    Published in PDFConverter
    Wednesday, 18 May 2011 09:59

    How to Convert HTML to PDF

    Why Convert HTML to PDF?

    PDF (Portable Document Format), which often used for printing document is an open standard for creating and sharing document. It is one of the most popular file formats because it retains the same format no matter what browser is used to view it and without any loss when transfer from one system to another. So, we usually convert different format files such as Doc, Text, CSV, XML and HTML to PDF. Here is one of the easiest and fastest solutions.

    How to Convert HTML to PDF?

    Only 3 simple steps, you can finish a whole process of HTML to PDF conversion by using Spire PDF Converter.
    Spire Free PDF Converter can help you finish conversion
    Spire PDF Converter Pro can help you finish conversion and encrypt & Watermark

    Step 1, Install and Run Spire PDF Converter

    Step 2, Add HTML files

    Spire PDF Converter enables user add single HTML file or multiple HTML files. And support add file folder.

    Step 3, Choose output file folder and Run conversion process

    Spire PDF Converter is one of the fastest HTML to PDF converting solutions. By using Spire PDF Converter, you can encrypt or add watermark to output PDF files.

    Free Download Spire PDF Converter(Free/Pro) Right Now!
    Published in PDFConverter
    Monday, 16 May 2011 10:04

    How to Convert Doc to PDF

    Why Convert Doc to PDF?

    PDF documents are not good for designing and editing content but without any information and appearance loss, they are very safe and easy to transfer from one system to another. On the other hand, Microsoft Word document (.doc file) is the most suitable document for designing and editing. So, the most popular way to create PDF documents is to design and create content in MS Word document and then convert the file from Doc to PDF.

    How to Convert Doc to PDF?

    Only 3 simple steps, you can finish a whole process of Doc to PDF conversion by using Spire PDF Converter.

    Step 1, Install and Run Spire PDF Converter

    Step 2, Choose Doc file

    Click button “Add files” to select Doc files which you want to convert. Spire PDF Converter supports batch conversion which means you can add multiple Doc files.

    Step 3, Start Converting

    Choose output file folder and click button "Convert"
    Free Download Spire PDF Converter Right Now!
    Published in PDFConverter
    Thursday, 20 January 2011 08:42

    How to Create Table in Word Document

    Sometimes, in order to give readers a better explanation, we may need to insert or create a table to show data information. Although Word table is not convenient as Excel, it is useful when we need to display data among one paragraph. As a powerful .NET/Silverlight Word component, Spire.Doc enables developers to create table in Word document with C#/VB.NET.

    How to Use C#/VB.NET to Create a Word Table via Spire.Doc

    In Spire.Doc, you need only four steps to insert or create a table in word document.

    Step 1 Creating a table

    You may use section.AddTable() method to create a table object in the section. Something should be paid attention, the table class in Spire.Doc is Spire.Doc.Table.
    [C#]
                //Create word document.
                Document document = new Document();
                
                //Add a section in the document.
                Section section = document.AddSection();
     
                //Create a table.
                Spire.Doc.Table table = section.AddTable();
              
    [Visual Basic]
            'Create word document.
            Dim document As New Document()
    
            'Add a section in the document.
            Dim section As Section = document.AddSection()
    
    
            'Create a table.
            Dim table As Spire.Doc.Table = section.AddTable()
              

    Step 2 Setting size of the table

    You should use table.ResetCells method to specify how many rows and columns the table has. In this method, you should give two number parameters, the first one is the number of the rows, the other one is the number of the columns.
    [C#]
                //Set table size.
                table.ResetCells(data.Length + 1, header.Length);
    
                //***************** First Row *************************
                TableRow row = table.Rows[0];
                row.IsHeader = true;
    
                //Set the Height of the header.
                row.Height = 20; //unit: point, 1point = 0.3528 mm
    
                //Set the Height Type of the header.
                row.HeightType = TableRowHeightType.Exactly;
              
    [Visual Basic]
            'Set the Rows and Columns.
            table.ResetCells(data.Length + 1, header.Length)
    
            '***************** First Row *************************
            Dim row As TableRow = table.Rows(0)
            row.IsHeader = True
    
            'Set the Height of the header.
            row.Height = 20 'unit: point, 1point = 0.3528 mm
    
            'Set the Height Type of the header.
            row.HeightType = TableRowHeightType.Exactly
              

    Step 3 Filling table header (optinal)

    Usually, the first row of the table is the header, and you may operate the header. You can set the height and back color, and then fill data into it.
    [C#]
                //Fill the table with header.
                String[] header = { "Name", "Capital", "Continent", "Area", "Population" };
    
                    //Set the Back Color of the data.
                    dataRow.RowFormat.BackColor = Color.Empty;
                    
                    //"c" is the Column of the data.
                    for (int c = 0; c < data[r].Length; c++)
                    {
                        
                        //Set the Cell Format of the data.
                        dataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                        
                        //Fill the Cell Format with the data.
                        dataRow.Cells[c].AddParagraph().AppendText(data[r][c]);
                    }
              
    [Visual Basic]
            'Fill the table with header.
            Dim header As String() = {"Name", "Capital", "Continent", "Area", "Population"}
    
                'Set the Back Color of the data.
                dataRow.RowFormat.BackColor = Color.Empty
    
                '"c" is the Column of the data.
                For c As Integer = 0 To data(r).Length - 1
    
                    'Set the Cell Format of the data.
                    dataRow.Cells(c).CellFormat.VerticalAlignment = VerticalAlignment.Middle
    
                    'Fill the Cell Format with the data.
                    dataRow.Cells(c).AddParagraph().AppendText(data(r)(c))
                Next
              

    Step 4 Filling table data

    The same with table data, you can set the height, alignment and back color of it, and then fill data into it.
    [C#]
                String[][] data =
        {
            new String[]{"Argentina", "Buenos Aires", "South America", "2777815", "32300003"},
            new String[]{"Bolivia", "La Paz", "South America", "1098575", "7300000"},
            new String[]{"Brazil", "Brasilia", "South America", "8511196", "150400000"},
            new String[]{"Canada", "Ottawa", "North America", "9976147", "26500000"},
            new String[]{"Chile", "Santiago", "South America", "756943", "13200000"},
            new String[]{"Colombia", "Bagota", "South America", "1138907", "33000000"},
            new String[]{"Cuba", "Havana", "North America", "114524", "10600000"},
            new String[]{"Ecuador", "Quito", "South America", "455502", "10600000"},
            new String[]{"El Salvador", "San Salvador", "North America", "20865", "5300000"},
            new String[]{"Guyana", "Georgetown", "South America", "214969", "800000"},
            new String[]{"Jamaica", "Kingston", "North America", "11424", "2500000"},
            new String[]{"Mexico", "Mexico City", "North America", "1967180", "88600000"},
            new String[]{"Nicaragua", "Managua", "North America", "139000", "3900000"},
            new String[]{"Paraguay", "Asuncion", "South America", "406576", "4660000"},
            new String[]{"Peru", "Lima", "South America", "1285215", "21600000"},
            new String[]{"United States of America", "Washington", "North America", "9363130",
                            "249200000"},
            new String[]{"Uruguay", "Montevideo", "South America", "176140", "3002000"},
            new String[]{"Venezuela", "Caracas", "South America", "912047", "19700000"}
        };
              
    [Visual Basic]
            Dim data As String()() = { _
                New String() {"Argentina", "Buenos Aires", "South America", "2777815", "32300003"}, _
                New String() {"Bolivia", "La Paz", "South America", "1098575", "7300000"}, _
                New String() {"Brazil", "Brasilia", "South America", "8511196", "150400000"}, _
                New String() {"Canada", "Ottawa", "North America", "9976147", "26500000"}, _
                New String() {"Chile", "Santiago", "South America", "756943", "13200000"}, _
                New String() {"Colombia", "Bagota", "South America", "1138907", "33000000"}, _
                New String() {"Cuba", "Havana", "North America", "114524", "10600000"}, _
                New String() {"Ecuador", "Quito", "South America", "455502", "10600000"}, _
                New String() {"El Salvador", "San Salvador", "North America", "20865", "5300000"}, _
                New String() {"Guyana", "Georgetown", "South America", "214969", "800000"}, _
                New String() {"Jamaica", "Kingston", "North America", "11424", "2500000"}, _
                New String() {"Mexico", "Mexico City", "North America", "1967180", "88600000"}, _
                New String() {"Nicaragua", "Managua", "North America", "139000", "3900000"}, _
                New String() {"Paraguay", "Asuncion", "South America", "406576", "4660000"}, _
                New String() {"Peru", "Lima", "South America", "1285215", "21600000"}, _
                New String() {"United States of America", "Washington", "North America", "9363130", _
                                "249200000"}, _
                New String() {"Uruguay", "Montevideo", "South America", "176140", "3002000"}, _
                New String() {"Venezuela", "Caracas", "South America", "912047", "19700000"} _
                }
              
    Full Code of C#/VB.NET Create Table in Word document:
    [C#]
    using Spire.Doc.Documents;
    using Spire.Doc;
    using System.Drawing;
    using Spire.Doc.Fields;
    using System;
    
    
    namespace InsertingComments
    {
    
        class Program
        {
            static void Main(string[] args)
            {
                //Create word document.
                Document document = new Document();
                
                //Add a section in the document.
                Section section = document.AddSection();
                
                //Fill the table with header.
                String[] header = { "Name", "Capital", "Continent", "Area", "Population" };
                String[][] data =
        {
            new String[]{"Argentina", "Buenos Aires", "South America", "2777815", "32300003"},
            new String[]{"Bolivia", "La Paz", "South America", "1098575", "7300000"},
            new String[]{"Brazil", "Brasilia", "South America", "8511196", "150400000"},
            new String[]{"Canada", "Ottawa", "North America", "9976147", "26500000"},
            new String[]{"Chile", "Santiago", "South America", "756943", "13200000"},
            new String[]{"Colombia", "Bagota", "South America", "1138907", "33000000"},
            new String[]{"Cuba", "Havana", "North America", "114524", "10600000"},
            new String[]{"Ecuador", "Quito", "South America", "455502", "10600000"},
            new String[]{"El Salvador", "San Salvador", "North America", "20865", "5300000"},
            new String[]{"Guyana", "Georgetown", "South America", "214969", "800000"},
            new String[]{"Jamaica", "Kingston", "North America", "11424", "2500000"},
            new String[]{"Mexico", "Mexico City", "North America", "1967180", "88600000"},
            new String[]{"Nicaragua", "Managua", "North America", "139000", "3900000"},
            new String[]{"Paraguay", "Asuncion", "South America", "406576", "4660000"},
            new String[]{"Peru", "Lima", "South America", "1285215", "21600000"},
            new String[]{"United States of America", "Washington", "North America", "9363130",
                            "249200000"},
            new String[]{"Uruguay", "Montevideo", "South America", "176140", "3002000"},
            new String[]{"Venezuela", "Caracas", "South America", "912047", "19700000"}
        };
    
                //Create a table.
                Spire.Doc.Table table = section.AddTable();
    
                //Set table size.
                table.ResetCells(data.Length + 1, header.Length);
    
                //***************** First Row *************************
                TableRow row = table.Rows[0];
                row.IsHeader = true;
    
                //Set the Height of the header.
                row.Height = 20; //unit: point, 1point = 0.3528 mm
    
                //Set the Height Type of the header.
                row.HeightType = TableRowHeightType.Exactly;
    
                //Set the Back Color of the header.
                row.RowFormat.BackColor = Color.Gray;
                for (int i = 0; i < header.Length; i++)
                {
    
                    //Set the Cell Format of the header.
                    row.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                    Paragraph p = row.Cells[i].AddParagraph();
                    
                    //Set the Horizon of the header.
                    p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
                    TextRange txtRange = p.AppendText(header[i]);
                    
                    //Set the Character Format of the header.
                    txtRange.CharacterFormat.Bold = true;
                }
    
                //***************** Data Row *************************
                for (int r = 0; r < data.Length; r++)
                {
                    TableRow dataRow = table.Rows[r + 1];
                    
                    //Set the Height of the data.
                    dataRow.Height = 20;
                    
                    //Set the Height Type of the data.
                    dataRow.HeightType = TableRowHeightType.Exactly;
                    
                    //Set the Back Color of the data.
                    dataRow.RowFormat.BackColor = Color.Empty;
                    
                    //"c" is the Column of the data.
                    for (int c = 0; c < data[r].Length; c++)
                    {
                        
                        //Set the Cell Format of the data.
                        dataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                        
                        //Fill the Cell Format with the data.
                        dataRow.Cells[c].AddParagraph().AppendText(data[r][c]);
                    }
                }
    
                //Save doc file.
                document.SaveToFile("Sample.doc", FileFormat.Doc);
    
                //Launch the file.
                System.Diagnostics.Process.Start("Sample.doc");
            }
        }
    }
              
    [Visual Basic]
    Imports Spire.Doc
    Imports Spire.Doc.Documents
    Imports System.Drawing
    Imports System
    Imports Spire.Doc.Fields
    
    Module Module1
    
        Sub Main()
            'Create word document.
            Dim document As New Document()
    
            'Add a section in the document.
            Dim section As Section = document.AddSection()
    
            'Fill the table with header.
            Dim header As String() = {"Name", "Capital", "Continent", "Area", "Population"}
            Dim data As String()() = { _
                New String() {"Argentina", "Buenos Aires", "South America", "2777815", "32300003"}, _
                New String() {"Bolivia", "La Paz", "South America", "1098575", "7300000"}, _
                New String() {"Brazil", "Brasilia", "South America", "8511196", "150400000"}, _
                New String() {"Canada", "Ottawa", "North America", "9976147", "26500000"}, _
                New String() {"Chile", "Santiago", "South America", "756943", "13200000"}, _
                New String() {"Colombia", "Bagota", "South America", "1138907", "33000000"}, _
                New String() {"Cuba", "Havana", "North America", "114524", "10600000"}, _
                New String() {"Ecuador", "Quito", "South America", "455502", "10600000"}, _
                New String() {"El Salvador", "San Salvador", "North America", "20865", "5300000"}, _
                New String() {"Guyana", "Georgetown", "South America", "214969", "800000"}, _
                New String() {"Jamaica", "Kingston", "North America", "11424", "2500000"}, _
                New String() {"Mexico", "Mexico City", "North America", "1967180", "88600000"}, _
                New String() {"Nicaragua", "Managua", "North America", "139000", "3900000"}, _
                New String() {"Paraguay", "Asuncion", "South America", "406576", "4660000"}, _
                New String() {"Peru", "Lima", "South America", "1285215", "21600000"}, _
                New String() {"United States of America", "Washington", "North America", "9363130", _
                                "249200000"}, _
                New String() {"Uruguay", "Montevideo", "South America", "176140", "3002000"}, _
                New String() {"Venezuela", "Caracas", "South America", "912047", "19700000"} _
                }
    
            'Create a table.
            Dim table As Spire.Doc.Table = section.AddTable()
    
            'Set the Rows and Columns.
            table.ResetCells(data.Length + 1, header.Length)
    
            '***************** First Row *************************
            Dim row As TableRow = table.Rows(0)
            row.IsHeader = True
    
            'Set the Height of the header.
            row.Height = 20 'unit: point, 1point = 0.3528 mm
    
            'Set the Height Type of the header.
            row.HeightType = TableRowHeightType.Exactly
    
            'Set the Back Color of the header.
            row.RowFormat.BackColor = Color.Gray
            For i As Integer = 0 To header.Length - 1
    
                'Set the Cell Format of the header.
                row.Cells(i).CellFormat.VerticalAlignment = VerticalAlignment.Middle
                Dim p As Paragraph = row.Cells(i).AddParagraph()
    
                'Set the Horizon of the header.
                p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center
                Dim txtRange As TextRange = p.AppendText(header(i))
    
                'Set the Character Format of the header.
                txtRange.CharacterFormat.Bold = True
            Next
    
            '***************** Data Row *************************
            For r As Integer = 0 To data.Length - 1
                Dim dataRow As TableRow = table.Rows(r + 1)
    
                'Set the Height of the data.
                dataRow.Height = 20
    
                'Set the Height Type of the data.
                dataRow.HeightType = TableRowHeightType.Exactly
    
                'Set the Back Color of the data.
                dataRow.RowFormat.BackColor = Color.Empty
    
                '"c" is the Column of the data.
                For c As Integer = 0 To data(r).Length - 1
    
                    'Set the Cell Format of the data.
                    dataRow.Cells(c).CellFormat.VerticalAlignment = VerticalAlignment.Middle
    
                    'Fill the Cell Format with the data.
                    dataRow.Cells(c).AddParagraph().AppendText(data(r)(c))
                Next
            Next
    
            'Save doc file.
            document.SaveToFile("Sample.doc", FileFormat.Doc)
    
            'Launch the file.
            System.Diagnostics.Process.Start("Sample.doc")
        End Sub
    End Module  
              

    Spire.Doc is an MS Word component which enables user to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document for .NET and Silverlight. Click to learn more...
    Published in Program Guide
    Wednesday, 19 January 2011 06:38

    How to Set Word Indent with C#/VB.NET

    Why We Set Word Indent?

    Word indent means to determine the distance of the paragraph margin from either the left or right. You can decrease or increase the indentation of a paragraph or several pargraphs within the margins. You will get a lot of choices when you set word indent. You can indent only the first line of a paragraph, increase or decrease the left/right of a whole paragraph, indent all but the first line of a paragraph, set indent by using the TAB key and create a negative indent, also known as Outdent which pulls paragraph out toward the left margin. When you set indentation of Word paragraphs, you can highlight group of paragraphs or even your whole word document to affect all selected paragraphs. In order to get a feel for how indentation functions work and how you can use them effortlessly in your word document, play around with the indent markers.

    In Microsoft Office Word document, the benefits of using the indent markers to indent or "tab" your paragraphs is to make sure suitable alignment. Furthermore, indent markers save you additional keystrokes because the indents you set are carried down to the next paragraph each time when you press Enter. The key to a well-formatted and professional-looking document is well setting indents in your Word document.

    The feature of Word indent is very convenient if you want to change indents in a large word document. You can select content that you want to change its indents at once through moving the indent markers to the desired location.

    How to Use Spire.Doc for .NET to Set Word Indent?

    Spire.Doc presents you an easy way to set word indent. There are two formats of indent paragraphs. One is list format, the other one is paragraph format.

    List Format

    In this format, you may write some paragraphs, and then use paragraph.ListFormat.ApplyBulletStyle() method to apply a style to the paragraphs for the bullet style. Also, you can customize a style, and apply the style to the paragraphs which need to be set indent. What's more, you can control the position of the points or numbers by assigning the paragraph.ListFormat.CurrentListLevel.NumberPosition property.
    Use the C#/VB.NET codes of Spire.Doc for .NET below to set Word indent as a list in Word document:
    [C#]
    using Spire.Doc.Documents;
    using Spire.Doc;
    using System;
    
    namespace ListIndent
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Create word document.
                Document document = new Document();
    
                //Add a section in the document.
                Section section = document.AddSection();
    
                //Add a paragraph 
                Paragraph paragraph = section.AddParagraph();
                paragraph.AppendText("Using items list to show Indent demo.");
                paragraph.ApplyStyle(BuiltinStyle.Heading3);
                
                //Indent list
                for (int i = 0; i < 10; i++)
                {
                    paragraph = section.AddParagraph();
                    paragraph.AppendText(String.Format("Indent Demo Node{0}", i));
                    if (i == 0)
                    {
                        paragraph.ListFormat.ApplyBulletStyle();
                    }
                    else
                    {
                        paragraph.ListFormat.ContinueListNumbering();
                    }
                    paragraph.ListFormat.CurrentListLevel.NumberPosition = -10;
                }
    
                //Save doc file.
                document.SaveToFile("Sample.doc", FileFormat.Doc);
    
                //Launch the file.
                System.Diagnostics.Process.Start("Sample.doc");
            }
        }
    }
              
    [Visual Basic]
    Imports Spire.Doc
    Imports Spire.Doc.Documents
    Imports System
    Imports Spire.Doc.Fields
    
    Module Module1
    
        Sub Main()
            'Create a document
            Dim document As New Document()
    
            'Get the first secition
            Dim section As Section = document.AddSection()
    
            'Add a paragraph
            Dim paragraph As Paragraph = section.AddParagraph
            
            'Append Text
            paragraph.AppendText("Using items list to show Indent demo.")
            paragraph.ApplyStyle(BuiltinStyle.Heading3)
    
            'Indent list 
            For i As Integer = 0 To 9
                paragraph = section.AddParagraph()
                Dim text As String = "Indent Demo Node" & i.ToString()
                Dim txtRange As TextRange = paragraph.AppendText(text)
                If i = 0 Then
                    paragraph.ListFormat.ApplyBulletStyle()
                Else
                    paragraph.ListFormat.ContinueListNumbering()
                End If
                paragraph.ListFormat.CurrentListLevel.NumberPosition = -10
            Next i
    
            'Save doc file.
            document.SaveToFile("Sample.doc", FileFormat.Doc)
    
            'Launching the MS Word file.
            System.Diagnostics.Process.Start("Sample.doc")
        End Sub
    End Module
              

    Paragraph Format

    In this format, also you should write some paragraphs, and then set the left indent distance by assigning the paragraph.Format.LeftIndent property.
    The paragraph format of indent paragraphs:
    [C#]
    using Spire.Doc.Documents;
    using Spire.Doc;
    using System;
    
    namespace ParagraphIndent
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Create word document.
                Document document = new Document();
    
                //Add a section in the document.
                Section section = document.AddSection();
    
                //Add a paragraph 
                Paragraph paragraph = section.AddParagraph();
                paragraph.AppendText("Using items list to show Indent demo.");
                paragraph.ApplyStyle(BuiltinStyle.Heading3);
                
                //Indent paragraphs
                for (int i = 0; i < 10; i++)
                {
                    paragraph = section.AddParagraph();
                    paragraph.AppendText(String.Format("Indent Demo Node{0}", i));
                    
                    //Set the indent distance of the left
                    paragraph.Format.LeftIndent = 15;
                }
    
                //Save doc file.
                document.SaveToFile("Sample.doc", FileFormat.Doc);
    
                //Launch the file.
                System.Diagnostics.Process.Start("Sample.doc");
            }
        }
    }
              
    [Visual Basic]
    Imports Spire.Doc
    Imports Spire.Doc.Documents
    Imports System
    Imports Spire.Doc.Fields
    
    Module Module1
    
        Sub Main()
            'Create a document
            Dim document As New Document()
    
            'Get the first secition
            Dim section As Section = document.AddSection()
    
            'Add a paragraph
            Dim paragraph As Paragraph = section.AddParagraph
            
            'Append Text
            paragraph.AppendText("Using items list to show Indent demo.")
            paragraph.ApplyStyle(BuiltinStyle.Heading3)
    
            'Indent paragraphs
            For i As Integer = 0 To 9
                paragraph = section.AddParagraph()
                Dim text As String = "Indent Demo Node" & i.ToString()
                Dim txtRange As TextRange = paragraph.AppendText(text)
                
                'Set the indent distance of the left
                paragraph.Format.LeftIndent = 15;
            Next i
    
            'Save doc file.
            document.SaveToFile("Sample.doc", FileFormat.Doc)
    
            'Launching the MS Word file.
            System.Diagnostics.Process.Start("Sample.doc")
        End Sub
    End Module
              
    Published in Program Guide
    Wednesday, 19 January 2011 06:30

    How to Insert a Page Break

    Sometimes, in order to identify the location of character segmentation, we may use break when converting table to text, or identify the beginning of new row or column when converting text to table. In Microsoft Word, there are kinds of types of break, page break, column break and newline. Among the three types, the frequently used is page break in Word document. Now, let’s learn the way to insert a page break.

    How to Insert a Page Break with Spire.Doc

    Spire.Doc presents an easy way to insert a page break. Just follow the simple steps below to insert a page break.

    Step 1

    Download Spire.Doc (Spire.Office) and install on system. Create a project and add Spire.Doc DLL as reference.

    Step 2

    Load word document which you need insert page break by usng the following code:
                Document document = new Document();
                document.LoadFromFile(@"D:\Sample.doc");
    

    Step 3

    We can insert page break among paragraphs. The code below is showing us how to insert page break between paragraphs.
            private void InsertBreak(Document document)
            {
                Section section = document.Sections[0];
                Paragraph paragraph = section.Paragraphs[2];
                paragraph.AppendBreak(BreakType.PageBreak);
            }
    

    Step 4

    Save the word document by using the following code:
                //Save doc file.
                document.SaveToFile("Sample.doc", FileFormat.Doc);
    
    Below is a full sample for both C# and VB.NET
    [C#]
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Spire.Doc;
    using Spire.Doc.Documents;
    
    namespace pagebreak
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                //Create word document
                Document document = new Document();
                document.LoadFromFile(@"D:\Sample.doc");
    
                InsertBreak(document);
    
                //Save doc file.
                document.SaveToFile("Sample.doc", FileFormat.Doc);
    
                //Launching the MS Word file.
                WordDocViewer("Sample.doc");
    
            }
            private void InsertBreak(Document document)
            {
                Section section = document.Sections[0];
                Paragraph paragraph = section.Paragraphs[2];
                paragraph.AppendBreak(BreakType.PageBreak);
            }
    
            private void WordDocViewer(string fileName)
            {
                try
                {
                    System.Diagnostics.Process.Start(fileName);
                }
                catch { }
            }
        }
    }
    [Visual Basic]
    Imports System
    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Linq
    Imports System.Text
    Imports System.Windows.Forms
    Imports Spire.Doc
    Imports Spire.Doc.Documents
    
    Namespace pagebreak
    	Partial Public Class Form1
    		Inherits Form
    		Public Sub New()
    			InitializeComponent()
    		End Sub
    
    		Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    			'Create word document
    			Dim document As New Document()
    			document.LoadFromFile("D:\Sample.doc")
    
    			InsertBreak(document)
    
    			'Save doc file.
    			document.SaveToFile("Sample.doc", FileFormat.Doc)
    
    			'Launching the MS Word file.
    			WordDocViewer("Sample.doc")
    
    		End Sub
    		Private Sub InsertBreak(ByVal document As Document)
    			Dim section As Section = document.Sections(0)
    			Dim paragraph As Paragraph = section.Paragraphs(2)
    			paragraph.AppendBreak(BreakType.PageBreak)
    		End Sub
    
    		Private Sub WordDocViewer(ByVal fileName As String)
    			Try
    				System.Diagnostics.Process.Start(fileName)
    			Catch
    			End Try
    		End Sub
    	End Class
    End Namespace
    Effective Screenshot:
    Published in Program Guide
    Tuesday, 18 January 2011 05:53

    How to Insert Comment in Word

    Why Do We Insert Comment in Word?

    The comments feature functions are much like Track Changes. It is used to insert information without overwriting the original text. You can use comments to ask the author questions or indicate an area that is unclear to you. And of course, the comment from the author will make it easier to understand the ideas coming from the author. Inserting comment in Word is good for us. So we need to insert comment in Word some time.

    How to Insert Comment in Microsoft Word?

    Open the reviewing toolbar for working with Comments:
  • Word 2000: Open the Reviewing Toolbar by clicking on View > Toolbars > Reviewing or simply select View > Comments.
  • Word 2002-2003: Change the setting in the 'Display for Review' option on the Reviewing Toolbar to 'Final Showing Markup' or click on the Reviewing Pane on the Reviewing Toolbar.
  • Word 2007: Change the setting in the 'Display for Review' option on the Review tab to 'Final Showing Markup' or click on the Reviewing Pane on the Review tab.
  • Otherwise, In some versions of MS Word (including Word for Mac OS X) you can select Insert > Comment, it will enable you to insert Comment in Word.

    How to Insert Comment in Word with Spire.Doc?

    Spire.Doc presents you an easy way to insert a comment into the word document. There are two forms of the comment in Spire.Doc, one is simple, the other is a little complex.

    Simple Comment

    Also, we suppose you have written text in the word document. Now you can specify a position to make a comment. Also you can set the author and the initial of the comment in comment.Format.Author and comment.Format.Initial methods.
    The following code is about the simple comment with C#.
    [C#]
    using System;
    using System.Drawing;
    using Spire.Doc;
    using Spire.Doc.Documents;
    using Spire.Doc.Fields;
    
    namespace MailMerge
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Create a new document 
                Document document = new Document();
                
                //Create a section
                Section section = document.AddSection();
                
                //Add a paragraph
                Paragraph paragraph = section.AddParagraph();
                
                //Style
                ParagraphStyle style = new ParagraphStyle(section.Document);
                style.Name = "style";
                style.ApplyBaseStyle(style.Name);
                style.CharacterFormat.Font = new Font("Arial", 10f);
                section.Document.Styles.Add(style);
                
                //Add a text
                String str = "Science (from the Latin scientia, meaning \"knowledge\") ";
                paragraph.AppendText(str);
    
                //Simple comment
                Comment comment = paragraph.AppendComment("Not given in this file.");
                comment.Format.Author = "Harry Hu";
                comment.Format.Initial = "HH";
                paragraph.ApplyStyle(style.Name);
                
                //Save doc file.
                document.SaveToFile("Sample.doc", FileFormat.Doc);
    
                //Launching the MS Word file.
                System.Diagnostics.Process.Start("Sample.doc");
            }
        }
    }
              
    The following code is about the simple comment with VB.NET.
    [Visual Basic]
    Imports System;
    Imports System.Drawing;
    Imports Spire.Doc;
    Imports Spire.Doc.Documents;
    Imports Spire.Doc.Fields;
    
    Module Module1
    
        Sub Main()
            'Create a new document
            Dim document As New Document()
            
            'Create a section
            Dim section As Section = document.AddSection()
                
            'Add a paragraph 
            Dim paragraph As Paragraph = section.AddParagraph()
            
            'Style
            Dim style As New ParagraphStyle = ParagraphStyle(section.Document)
            style.Name = "style"
            style.ApplyBaseStyle(style.Name)
            style.CharacterFormat.Font = new Font("Arial", 10f)
            section.Document.Styles.Add(style)
            
            'Add a text
            Dim str As String  = "Science (from the Latin scientia, meaning ""knowledge"") "
            paragraph.AppendText(str)
    
            'Simple comment
            Dim comment As Comment  = paragraph.AppendComment("Not given in this file.")
            comment.Format.Author = "Harry Hu"
            comment.Format.Initial = "HH"
            paragraph.ApplyStyle(style.Name)
            
            'Save the file
            workbook.SaveToFile("Sample.doc")
            
            'Launch the file
            System.Diagnostics.Process.Start("Sample.doc")
        End Sub
    End Module
              

    Complex Comment

    Here, we suppose you have written text in your word document. Now you may use paragraph.AppendComment("comment text") method to insert your comment into the document. And then, you may use comment.AddItem(text) to specify the text which you are making comment for. You can set the author and initial of the comment in comment.Format.Author and comment.Format.Initial methods.
    The following code is about the complex comment with C#:
    [C#]
    using System;
    using System.Drawing;
    using Spire.Doc;
    using Spire.Doc.Documents;
    using Spire.Doc.Fields;
    
    namespace MailMerge
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Create a new document 
                Document document = new Document();
                
                //Create a section
                Section section = document.AddSection();
                
                //Add a paragraph
                Paragraph paragraph = section.AddParagraph();
    
                //style
                ParagraphStyle style = new ParagraphStyle(section.Document);
                style.Name = "style";
                style.CharacterFormat.FontName = "Arial";
                style.CharacterFormat.FontSize = 9;
                style.ParagraphFormat.LineSpacing = 1.5F * 12F;
                style.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple;
                section.Document.Styles.Add(style);
    
                //Add a paragraph
                paragraph = section.AddParagraph();
                paragraph.AppendText("(All text and pictures are from ");
                
                //Append the text which you want to make comment for
                TextRange text = paragraph.AppendText("Wikipedia");
    
                //Make comment 
                Comment comment = paragraph.AppendComment("http://en.wikipedia.org/wiki/Science");
                comment.AddItem(text);
                comment.Format.Author = "Harry Hu";
                comment.Format.Initial = "HH";
                
                //Continue the paragraph
                paragraph.AppendText(", the free encyclopedia)");
                paragraph.ApplyStyle(style.Name);
          
                //Save doc file.
                document.SaveToFile("Sample.doc", FileFormat.Doc);
    
                //Launching the MS Word file.
                System.Diagnostics.Process.Start("Sample.doc");
            }
        }
    }
              
    The following code is about the complex comment with VB.NET:
    [Visual Basic]
    Imports System;
    Imports System.Drawing;
    Imports Spire.Doc;
    Imports Spire.Doc.Documents;
    Imports Spire.Doc.Fields;
    
    Module Module1
    
        Sub Main()
            'Create a new document
            Dim document As New Document()
            
            'Create a section
            Dim section As Section = document.AddSection()
            
            'Add a paragraph 
            Dim paragraph As Paragraph = section.AddParagraph()
            
            'Style
            Dim style As New ParagraphStyle = ParagraphStyle(section.Document)
            style.Name = "style"
            style.CharacterFormat.FontName = "Arial"
            style.CharacterFormat.FontSize = 9
            style.ParagraphFormat.LineSpacing = 1.5F * 12F
            style.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple
            section.Document.Styles.Add(style);
            
            'Add a paragraph 
            Dim paragraph As Paragraph = section.AddParagraph()
            paragraph.AppendText("(All text and pictures are from ")
            
            'Append the text which you want to make comment for
            Dim text As TextRange = paragraph.AppendText("Wikipedia")
    
            'Make comment 
            Dim comment As Comment = paragraph.AppendComment("http://en.wikipedia.org/wiki/Science")
            comment.AddItem(text)
            comment.Format.Author = "Harry Hu"
            comment.Format.Initial = "HH"
                
            'Continue the paragraph
            paragraph.AppendText(", the free encyclopedia)")
            paragraph.ApplyStyle(style.Name)
            
            'Save the file
            workbook.SaveToFile("Sample.doc")
            
            'Launch the file
            System.Diagnostics.Process.Start("Sample.doc")
        End Sub
    End Module
              
    The full example demonstrates the comparison of the two styles.
    [C#]
    using System;
    using System.Drawing;
    using Spire.Doc;
    using Spire.Doc.Documents;
    using Spire.Doc.Fields;
    
    namespace MailMerge
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Create a new document 
                Document document = new Document();
                
                //Create a section
                Section section = document.AddSection();
                
                //Add a paragraph
                Paragraph paragraph = section.AddParagraph();
    
                //style1
                ParagraphStyle style1 = new ParagraphStyle(section.Document);
                style1.Name = "style";
                style1.CharacterFormat.FontName = "Arial";
                style1.CharacterFormat.FontSize = 9;
                style1.ParagraphFormat.LineSpacing = 1.5F * 12F;
                style1.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple;
                section.Document.Styles.Add(style1);
    
                //Add a paragraph
                paragraph = section.AddParagraph();
                paragraph.AppendText("(All text and pictures are from ");
                
                //Append the text which you want to make comment for
                TextRange text = paragraph.AppendText("Wikipedia");
    
                //Make complex comment 
                Comment comment1 = paragraph.AppendComment("http://en.wikipedia.org/wiki/Science");
                comment1.AddItem(text);
                comment1.Format.Author = "Harry Hu";
                comment1.Format.Initial = "HH";
                
                //Continue the paragraph
                paragraph.AppendText(", the free encyclopedia)");
                paragraph.ApplyStyle(style1.Name);
                
                //Style2
                ParagraphStyle style2 = new ParagraphStyle(section.Document);
                style2.Name = "style2";
                style2.ApplyBaseStyle(style1.Name);
                style2.CharacterFormat.Font = new Font("Arial", 10f);
                section.Document.Styles.Add(style2);
                
                //Add a second paragraph
                Paragraph paragraph1 = section.AddParagraph();
                
                //Add a text
                String str1 = "Science (from the Latin scientia, meaning \"knowledge\") ";
                paragraph1.AppendText(str1);
    
                //Simple comment
                Comment comment2 = paragraph.AppendComment("Not given in this file.");
                comment2.Format.Author = "Harry Hu";
                comment2.Format.Initial = "HH";
                paragraph.ApplyStyle(style2.Name);
                
                //Save doc file.
                document.SaveToFile("Sample.doc", FileFormat.Doc);
    
                //Launching the MS Word file.
                System.Diagnostics.Process.Start("Sample.doc");
          
            }
        }
    }
              
    [Visual Basic]
    Imports System
    Imports System.Drawing
    Imports Spire.Doc
    Imports Spire.Doc.Documents
    Imports Spire.Doc.Fields
    
    Module Module1
    
        Sub Main()
            'Create a new document
            Dim document As New Document()
    
            'Create a section
            Dim section As Section = document.AddSection()
    
            'Add a paragraph 
            Dim paragraph As Paragraph = section.AddParagraph()
    
            'Style1
            Dim style1 As New ParagraphStyle(document)
            style1.Name = "style1"
            style1.CharacterFormat.FontName = "Arial"
            style1.CharacterFormat.FontSize = 9
            style1.ParagraphFormat.LineSpacing = 1.5F * 12.0F
            style1.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple
            section.Document.Styles.Add(style1)
    
            'Add a paragraph 
            paragraph = section.AddParagraph()
            paragraph.AppendText("(All text and pictures are from ")
    
            'Append the text which you want to make comment for
            Dim text As TextRange = paragraph.AppendText("Wikipedia")
    
            'Make complex comment 
            Dim comment1 As Comment = paragraph.AppendComment("http://en.wikipedia.org/wiki/Science")
            comment1.AddItem(text)
            comment1.Format.Author = "Harry Hu"
            comment1.Format.Initial = "HH"
    
            'Continue the paragraph
            paragraph.AppendText(", the free encyclopedia)")
            paragraph.ApplyStyle(style1.Name)
    
            'Style2
            Dim style2 As New ParagraphStyle(document)
            style2.Name = "style"
            style2.ApplyBaseStyle(style1.Name)
            style2.CharacterFormat.Font = New Font("Arial", 10.0F)
            section.Document.Styles.Add(style2)
    
            'Add a second paragraph
            Dim paragraph1 As Paragraph = section.AddParagraph()
    
            'Add a text
            Dim str1 As String = "Science (from the Latin scientia, meaning ""knowledge"") "
            paragraph1.AppendText(str1)
    
            'Simple comment
            Dim comment2 As Comment = paragraph.AppendComment("Not given in this file.")
            comment2.Format.Author = "Harry Hu"
            comment2.Format.Initial = "HH"
            paragraph.ApplyStyle(style2.Name)
    
            'Save the file
            document.SaveToFile("Sample.doc")
    
            'Launch the file
            System.Diagnostics.Process.Start("Sample.doc")
        End Sub
    End Module
              
    Published in Program Guide
    << Start < Prev 1 2 3 4 Next > End >>
    Page 1 of 4