4/26/2012

Add Excel Comment with C#, VB.NET

Everything is changing. So is the data information. When changes happen in excel, Comment provides great convenience for people to make notes about what has been changed. Besides, the old data information also can be kept. For example, your customer has changed his/her e-mail or contact, while you need use comment function to remind the author modify the information in time.

So how to make comment in excel with C#, VB.NET is the main point in this article. The whole procedure can be very easy since I use an excel creation component Spire.XLS to help me. You also can Freely Install Spire.XLS on the system.


How to add Excel comment with C#, VB.NET
Using Spire.XLS, I only need three steps to realize this task in a quick way. Please look at the below procedure.


Step1. Load an Excel file from System.

C# Code:
           //Load File
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"D:\michelle\e-iceblue\Spire.XLS\Demos\Data\comment.xlsx");
            Worksheet sheet = workbook.Worksheets[0];

VB.NET Code:
                          'Load File
                          Dim workbook As New Workbook()
                          workbook.LoadFromFile("D:\michelle\e-iceblue\Spire.XLS\Demos\Data\comment.xlsx")
                          Dim sheet As Worksheet = workbook.Worksheets(0)



Step2. Add comment in Excel.

C# Code:
            //Add Comment
            string str = "E-mail has been changed as c.white2304@gmail.com";
            ExcelFont font1 = workbook.CreateFont();
            font1.FontName = "Century Gothic";
            font1.Color = Color.DarkCyan;
            font1.IsBold = true;
            sheet.Range["A6"].Comment.RichText.Text = str;
            sheet.Range["A6"].Comment.Width = 200;
            sheet.Range["A6"].Comment.Height = 50;
            sheet.Range["A6"].Comment.RichText.SetFont(26, 47, font1);

VB.NET Code:
                          'Add Comment
                          Dim str As String = "E-mail has been changed as c.white2304@gmail.com"
                          Dim font1 As ExcelFont = workbook.CreateFont()
                          font1.FontName = "Century Gothic"
                          font1.Color = Color.DarkCyan
                          font1.IsBold = True

                          sheet.Range("A6").Comment.RichText.Text = str
                          sheet.Range("A6").Comment.Width = 200
                          sheet.Range("A6").Comment.Height = 50
                          sheet.Range("A6").Comment.RichText.SetFont(26, 47, font1)



Step3. Save and Launch the file.
C# Code:
            //Save and Launch
            workbook.SaveToFile("Comment.xlsx", ExcelVersion.Version2010);
            System.Diagnostics.Process.Start("Comment.xlsx");

VB.NET Code:
                          'Save and Launch
                          workbook.SaveToFile("Comment.xlsx", ExcelVersion.Version2010)
                          System.Diagnostics.Process.Start("Comment.xlsx")

Note: 1. Please choose .NET Framework4 as the Target framework.

            2. Add Spire.XLS DLL and System.Drawing as references.

            3. Add the following using at the top of the file.
C#
using System.Drawing;
using Spire.Xls;
using Spire.Xls.Core;


Preview


There are many other Excel functions that can be realized by C#, VB.NET. So if you want to consult more, please see below:

4/25/2012

How to Realize PDF Attachment Function for C#, VB.NET

PDF is so powerful that it can attach every kind of files in it, such as Word, Excel, Text, TTF, Images, PDF and so on, which escapes the trouble of converting these files to PDF documents, which also provides great convenience to use the information of these files. Thus, PDF attachment function is really useful and practical. While how to attach these files in PDF with C#, VB.NET is what we talk about in this article.

In this article, I will introduce an easy method to attach Word, Excel, Text, TTF files and Images in one PDF document with C#, VB.NET. Of course, you also can attach other files in it. During my method, I use a powerful PDF document creation component Spire.PDFto help me. It can be used on the server-side (ASP.NET or any other environment) or with Windows Forms applications. If you want to give it a try, you can Freely Install Spire.PDF in your system. Please look at the below procedure.





Procedure

Step1. Create a new project

1.     Create a new project in Visual Studio, and set its Target framework to be .NET Framework 4 in Properties.

2.     Add System. Drawing and Spire.PDF Dll as reference in Project.

3.     Add the below using at the top of the file.

C#
using System.Drawing;
using System.IO;
using Spire.Pdf;
using Spire.Pdf.Annotations;
using Spire.Pdf.Attachments;
using Spire.Pdf.Graphics;

Step2. Attach Word, Excel, TTF, Text and images in PDF document with C#, VB.NET.

1.     Create a new PDF document and set its margin, then, create a section in it and one page in the section.

C# Code:
           //Create a pdf document.
            PdfDocument doc = new PdfDocument();
            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;
            //create section
            PdfSection section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;           
           // Create one page
            PdfPageBase page = section.Pages.Add();
            float y = 10;

2.     Set the title of the PDF document.

C# Code:
            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Attachment", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Attachment", format1).Height;
            y = y + 5;

3.     Attach images in PDF document. Spire.PDF allows people attach different formats of images in it.

C# Code:
           //attach images
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Bold));
            PointF location = new PointF(0, y);
            String label = "Sales Report Chart";
            byte[] data = File.ReadAllBytes(@"D:\michelle\SalesReportChart.png");
            SizeF size = font2.MeasureString(label);
            RectangleF bounds = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation1
                = new PdfAttachmentAnnotation(bounds, "SalesReportChart.png", data);
            annotation1.Color = Color.Teal;
            annotation1.Flags = PdfAnnotationFlags.ReadOnly;
            annotation1.Icon = PdfAttachmentIcon.Graph;
            annotation1.Text = "Sales Report Chart";
            (page as PdfNewPage).Annotations.Add(annotation1);
            y = y + size.Height + 2;
            location = new PointF(0, y);
            label = "Science Personification Boston";
            data = File.ReadAllBytes(@"D:\michelle\SciencePersonificationBoston.jpg");
            size = font2.MeasureString(label);
            bounds = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation2
                = new PdfAttachmentAnnotation(bounds, "SciencePersonificationBoston.jpg", data);
            annotation2.Color = Color.Orange;
            annotation2.Flags = PdfAnnotationFlags.NoZoom;
            annotation2.Icon = PdfAttachmentIcon.PushPin;
            annotation2.Text = "SciencePersonificationBoston.jpg, from Wikipedia, the free encyclopedia";
            (page as PdfNewPage).Annotations.Add(annotation2);
            y = y + size.Height + 2;
            location = new PointF(0, y);
            label = "Picture of Science";
            data = File.ReadAllBytes(@"D:\michelle\Wikipedia_Science.png");
            size = font2.MeasureString(label);
            bounds = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation3
                = new PdfAttachmentAnnotation(bounds, "Wikipedia_Science.png", data);
            annotation3.Color = Color.SaddleBrown;
            annotation3.Flags = PdfAnnotationFlags.Locked;
            annotation3.Icon = PdfAttachmentIcon.Tag;
            annotation3.Text = "Wikipedia_Science.png, from Wikipedia, the free encyclopedia";
            (page as PdfNewPage).Annotations.Add(annotation3);
            y = y + size.Height + 2;

4.     Attach documents in PDF file. In this step, I attach a word, excel, text, ttf in it, if necessary,you also can attach other formats files such as html, xml,  tiff and so on.

C# Code:
           //attach ttf file
            location = new PointF(0, y);
            label = "Hawaii Killer Font";
            data = File.ReadAllBytes(@"D:\michelle\Hawaii_Killer.ttf");
            size = font2.MeasureString(label);
            bounds = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation4
                = new PdfAttachmentAnnotation(bounds, "Hawaii_Killer.ttf", data);
            annotation4.Color = Color.CadetBlue;
            annotation4.Flags = PdfAnnotationFlags.NoRotate;
            //annotation4.Icon = PdfAttachmentIcon.Paperclip;
            annotation4.Text = "Hawaii Killer Font, from http://www.1001freefonts.com";
            (page as PdfNewPage).Annotations.Add(annotation4);
            y = y + size.Height + 2;

            //attanch a word document
            location = new PointF(0, y);
            label = "Jane Eyre";
            data = File.ReadAllBytes(@"E:\JaneEyre.docx");
            size = font2.MeasureString(label);
            bounds = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation5
                = new PdfAttachmentAnnotation(bounds,"JaneEyre.docx" , data);
            annotation5.Color = Color.Green;
            annotation5.Flags = PdfAnnotationFlags.NoRotate;
            //annotation5.Icon = PdfAttachmentIcon.Paperclip;
            annotation5.Text = "JaneEyre, from http://www.encyclopaedia.com";
            (page as PdfNewPage).Annotations.Add(annotation5);
            y = y + size.Height + 2;

            //attach a txt file
            location = new PointF(0, y);
            label = "The Spring Festival";
            data = File.ReadAllBytes(@"E:\SpringFestival.txt");
            size = font2.MeasureString(label);
            bounds = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation6
                = new PdfAttachmentAnnotation(bounds, "SpringFestival.txt", data);
            annotation6.Color = Color.HotPink;
            annotation6.Flags = PdfAnnotationFlags.NoRotate;
            //annotation6.Icon = PdfAttachmentIcon.Paperclip;
            annotation6.Text = "The Spring Festival, from http://www.everlasting129.weebly.com";
            (page as PdfNewPage).Annotations.Add(annotation6);
            y = y + size.Height + 2;

            //attach an excel document
            location = new PointF(0, y);
            label = "Excel";
            data = File.ReadAllBytes(@"E:\excel.xlsx");
            size = font2.MeasureString(label);
            bounds = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation7
                = new PdfAttachmentAnnotation(bounds, "excel.xlsx", data);
            annotation7.Color = Color.OrangeRed;
            annotation7.Flags = PdfAnnotationFlags.NoRotate;
            //annotation7.Icon = PdfAttachmentIcon.Paperclip;
            annotation7.Text = "excel, from http://www.e-iceblue.com";
            (page as PdfNewPage).Annotations.Add(annotation7);
            y = y + size.Height + 2;

Step3. Save and launch the file.

C# Code:
            //Save pdf file.
            doc.SaveToFile("Attachment.pdf");
            doc.Close();

            //Launching the Pdf file.
            System.Diagnostics.Process.Start("Attachment.pdf");
Note: Because the code is too long, so if you need VB.NET, please use see the VB.NET Code.


Preview

Besides, PDF has many other functions. All can be realized by C#, VB.NET. If you want to know more, please consult by the below link.

More PDF Functions


Source

4/19/2012

How to Find and Replace Data in Excel with C#, VB.NET

Excel Find and Replace function can be effectively used to find a certain value in the text and replace it to another. Especially, when in a long excel document, it really takes much time to correctly find what you want and change it. The value you want to find maybe a data, a formula, a name or other text. Whatever it is,Spire.XLS, an excel component, can help you quickly realize this task in a few minutes. 


Excel Find and Replace with C#,VB.NET.
Using Spire.XLS,  you not only can replace data on the condition that you can find them directly with a few seconds, but also allows you to quickly look for what you need to replace in a long excel worksheet. Now, follow the blow steps to finish this task with C#, VB.NET.




Procedure
1.Create a workbook and load an excel file from the system.

2.Find and replace. I find "Asia" and replace it to "South American" in the column 20 and 21.

3.Save and launch the file.



Full Code:

C# Code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Xls;
namespace find_and_replace
{
    class Program
    {
        static void Main(string[] args)
        {
            //create a workbook
            Workbook workbook = new Workbook();
           workbook.LoadFromFile(@"C:\e-iceblue\employee.xls ", ExcelVersion.Version97to2003);
            Worksheet worksheet = workbook.Worksheets[0];

            //find and replace
            CellRange[] ranges = worksheet.FindAllString("Asia", false, false);
            foreach (CellRange range in ranges)
            {
                range.Text = "South American";
            }

            //save the workbook
            workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003);
            System.Diagnostics.Process.Start("sample.xls");
        }
    }
}



VB.NET Code:

Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports Spire.Xls
Namespace find_and_replace
         Class Program
                 Private Shared Sub Main(args As String())
                        'create a workbook                        
                         Dim workbook As New Workbook()
  workbook.LoadFromFile("C:\e-iceblue\employee.xls ", ExcelVersion.Version97to2003
                          Dim worksheet As Worksheet = workbook.Worksheets(0)
                        'find and replace                         
                    Dim ranges As CellRange() = worksheet.FindAllString("Asia", False, False)
                          For Each range As CellRange In ranges
                                   range.Text = "South American"
                          Next
                       'save the workbook                     
                        workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003)
                          System.Diagnostics.Process.Start("sample.xls")
                 End Sub
         End Class
End Namespace


Preview
original file
find and replace

Find and Replace is just a small function of Spire.XLS. Besides, Spire.XLS  have scores of other functions including the basic format of data, formula, worksheet edition, background color, image, security and so on.  Spire.XLS also can be converted to many other popular file formats such as PDF, HTML, XML, Image, CSV etc. Click to find more features about Spire.XLS.



How to Insert TextBox in Excel with C#,VB.NET

Excel is a professional document used to edit different data information in most cases. But sometimes, people need to insert some text also to explain, comment, remark or something else to help people understand the data information more clearly. Thus, insert textbox becomes necessary.  

In order to realize this task smoothly, I would like to use a .NET component Spire.XLS to help me insert textbox in excel with C#,VB.NET. Spire.XLS uses four steps to finish this task. So it is a good choice to install Spire.XLS in the system.



How to insert textbox in excel with C#,VB.NET
Before we start, please create a project in Visual Studio and set your target Framework to be .NET Framework 4. Then, add Spire.XLS DLL as the reference. When you add using Spire.XLS at the top of the method, please make sure that you also add using Spire.Xls.Core.


Procedure


Step1. Create a workbook and initialize worksheet.

Inset Textbox with C# Code:
Workbook workbook = new Workbook();
workbook.CreateEmptySheets(1);
Worksheet sheet = workbook.Worksheets[0];

Inset Textbox with VB.NET Code:
Dim workbook As New Workbook()
workbook.CreateEmptySheets(1)
Dim sheet As Worksheet = workbook.Worksheets(0)




Step2. Insert Texbox in excel.
In this step, I use the “ sheet. TextBoxes. AddTextBox()” method to insert textbox in excel. There are four parameters passed to this method: int row( textbox beginning row), int column(textbox beginning column), textbox height and width.

Inset Textbox with C# Code:
ITextBox textbox = sheet.TextBoxes.AddTextBox(4, 6, 200, 400);

Inset Textbox with VB.NET Code:
Dim textbox As ITextBox = sheet.TextBoxes.AddTextBox(4, 6, 200, 400)


Step3. Set texbox format
I set the text rotation to be left to right and set the text alignment. There are two types of alignment: vertical and horizontal. In this method, I set both types as center.

Inset Textbox with C# Code:
textbox.TextRotation = TextRotationType.LeftToRight;
textbox.HAlignment = CommentHAlignType.Center;
textbox.VAlignment = CommentVAlignType.Center;
textbox.Text = "Insert TextBox in Workbook";

Inset Textbox with VB.NET Code:
textbox.TextRotation = TextRotationType.LeftToRight
textbox.HAlignment = CommentHAlignType.Center
textbox.VAlignment = CommentVAlignType.Center
textbox.Text = "Insert TextBox in Workbook"

Step4. Save and launch the file
Inset Textbox with C# Code: 
workbook.SaveToFile("ExcelTextBox.xls", ExcelVersion.Version97to2003);
 System.Diagnostics.Process.Start("ExcelTextBox.xls");

Inset Textbox with VB.NET Code:
workbook.SaveToFile("ExcelTextBox.xls", ExcelVersion.Version97to2003)
System.Diagnostics.Process.Start("ExcelTextBox.xls")



Preview



You only need the above simple four steps to finish inserting textbox in excel with C#,VB.NET by using Spire.XLS. So why not give it a try? More excel functions realized with C#,VB,.NET can be found below:

More functions


4/16/2012

Set Text Alignment with C#,VB.NET

Word Text Alignment contains four styles: align left, align center, align right, and justify. All these kinds are frequently used when we set our word text styles. With the text alignment, our document text looks very clear and nice. Sometimes, people are specially asked to align the articles or papers in a certain alignment style. Thus, text alignment can be indispensable for word users. So I decide to write this post to meet people’s need. Before I show the method to alignment text in word with C#, VB.NET. I suggest use a word component Spire.Doc to help me finish this task.


Spire.Doc, can be used to perform a wide range of Word Document processing tasks directly without using Microsoft Word. It supports C#, VB.NET, ASP, .NET MVC and Silverlight. It has been widely used by the most Fortune 500 corporations. If you want to give it a try, please

Freely Download Spire.Doc




How to align text in word document with C#,VB.NET

The following procedure clearly shows you how to easily align text in word with C#,VB.NET by using Spire.Doc. Please follow it step by step:




Step1. Create a Project.

1.     Create a new project in Visual Studio, no need of Forms.

2.     Set the target Framework to be .NET Framework 4.

3.     Add Spire.Doc DLL as reference.

4.     Add Spire.Doc and Spire.Doc. Documents as using at the top of the method. Please see:

     C# 
        using Spire.Doc;
        using Spire.Doc.Documents;
        namespace Word_Alignment
        {
           class Program
          {
                  static void Main(string[] args)
              {
                …
               }
           }
        }
VB.NET 
       Imports Spire.Doc
       Imports Spire.Doc.Documents
        Namespace Word_Alignment
               Class Program
                   Private Shared Sub Main(args As String())
                   …
                   End Sub
               End Class
        End Namespace




Step2. Creat a Word Document.

C# Code:
  //Create a document
  Document document = new Document();
  //Create a section
  Section section = document.AddSection();

VB.NET Code:
 'Create a document
 Dim document As New Document()
 'Create a section
 Dim section As Section = document.AddSection()

Step3. Align text in word
C# Code:
            //Alignment left

            Paragraph paragraph1 = section.AddParagraph();
            paragraph1.AppendText(" Text Alignment- Left");
            paragraph1.Format.HorizontalAlignment = HorizontalAlignment.Left;
            //Alignment center
            Paragraph paragraph2 = section.AddParagraph();
            paragraph2.AppendText(" Text Alignment- Center");
            paragraph2.Format.HorizontalAlignment = HorizontalAlignment.Center;
            //Alignment right
            Paragraph paragraph3 = section.AddParagraph();
            paragraph3.AppendText(" Text Alignment- Right");
            paragraph3.Format.HorizontalAlignment = HorizontalAlignment.Right;
            //Alignment justify
            Paragraph paragraph4 = section.AddParagraph();
            paragraph4.AppendText("Microsoft Word is a word processor designed by Microsoft. It was first released in 1983 under the name Multi-Tool Word for Xenix systems. The demo Text demonstrates the horizontal alignment Justify");
            paragraph4.Format.HorizontalAlignment = HorizontalAlignment.Justify;

VB.NET Code:

           ‘Alignment left

            Dim paragraph1 As Paragraph = section.AddParagraph()
            paragraph1.AppendText(" Text Alignment- Left")
            paragraph1.Format.HorizontalAlignment = HorizontalAlignment.Left
            'Alignment center
            Dim paragraph2 As Paragraph = section.AddParagraph()
            paragraph2.AppendText(" Text Alignment- Center")
            paragraph2.Format.HorizontalAlignment = HorizontalAlignment.Center
            'Alignment right
            Dim paragraph3 As Paragraph = section.AddParagraph()
            paragraph3.AppendText(" Text Alignment- Right")
            paragraph3.Format.HorizontalAlignment = HorizontalAlignment.Right
            'Alignment justify
            Dim paragraph4 As Paragraph = section.AddParagraph()
            paragraph4.AppendText("Microsoft Word is a word processor designed by Microsoft. It was first released in 1983 under the name Multi-Tool Word for Xenix systems. The demo Text demonstrates the horizontal alignment Justify")
            paragraph4.Format.HorizontalAlignment = HorizontalAlignment.Justify
Step4.Save and launch the file.

C# Code:

            //Save doc file.
            document.SaveToFile("Sample.doc", FileFormat.Doc);
            //Launch the file.
            System.Diagnostics.Process.Start("Sample.doc");

VB.NET Code:
            //Save doc file.
            document.SaveToFile("Sample.doc", FileFormat.Doc)
            //Launch the file.
            System.Diagnostics.Process.Start("Sample.doc")


Preview


Text Alignment is just one of the Word Text Styles. Besides, there are many other styles in word, such as word color, word font, word indent and so on. Please see more articles about word text styles.




Source

4/12/2012

How to Convert Excel to HTML with C#, VB.NET

HTML (Hyper-Text Mark-up Language) is one of the most frequently used formats for people to display pages and upload information on internet. Beside, every program makes HTML code, each program including Mozilla Firefox and Internet Explorer use the program to show information that is programmed to display. Thus, html is very important for cyber citizens.

HTML can be converted by many file formats, such as Word and Excel. Also HTML can be converted to Word and PDF. Using Spire.XLS, you can easily convert Excel to HTML.


How to convert Excel to HTML with C#,VB.NET

Besides converting excel to HTML, Excel also can be converted to PDF, XML, Image, CSV .etc by using Spire.XLS. Please look at the below procedure.


Procedure

1. Create a workbook.

2. Load an excel file from the system.

3. Save the excel file to HTML format and Launch it.


Main Code:

C# Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Xls;
namespace excel2html
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"C:\Program Files\e-iceblue\Spire.XLS\Demos\Data\employee.xls");
            Worksheet sheet = workbook.Worksheets[0];
            sheet.SaveToHtml("sample.html");
            System.Diagnostics.Process.Start("sample.html");
        }
    }
}


 
VB.NET Code:

Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports Spire.Xls

Namespace excel2Html
        Class Program
               Shared Sub New(args As String())
                       Dim workbook As New Workbook()
                       workbook.LoadFromFile C:\Program Files\e-iceblue\Spire.XLS\Demos\Data\employee.xls")
                       Dim sheet As Worksheet = workbook.Worksheets(0)
                       sheet.SaveToHtml("sample.html")
               End Sub
        End Class
End Namespace



Preview

                                      


 Spire.XLS is a professional Excel component which enables developers/programmers to fast generate, read, write and modify Excel document for .NET and Silverlight. It supports C#, VB.NET, ASP.NET, ASP.NET MVC and Silverlight.

Freely Download Spire.XLS



Source

Easy Method to Convert HTML to PDF with C#,VB.NET

PDF (Portable Document Format), as I said in many former articles, owns a lot of functions, such as it meets Legal Document Requirements, a “read only” document which cannot be altered without leaving an electronic footprint, compression of a Scanned Image into a PDF File is Sizeable and so on.

Actually, the character of PDF format is far more, and I personally think that whenever how good this format is, if it cannot be converted by other file formats, its function cannot be fully used. So the reasons why PDF format is such popular should not be only attributed to the characteristics, but also its applicability. That means PDF can be converted by many file formats, also can be converted to various formats.

Today, I am very glad to share an easy method to convert HTML to PDF with C#,V.NET by using Spire.PDF, which is a PDF creation component that enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. Please follow the below steps.

 

Procedure

Step1. Create a PDF Document.

Step2. Load the HTML file from the system.

I insert a url directly in the project, you also can load an existing HTML file that you want to convert.

Step3. Save the HTML file to PDF format, and launch it.

Main code:

Convert HTML to PDF with C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Pdf;
namespace HTML2PDF
{
    class Program
    {
        [STAThread]//do not lose it if your project is not in single thread        static void Main(string[] args)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
            String url = http://www.e-iceblue.com/;
            doc.LoadFromHTML(url, false, true, true);
            //Save pdf file.
            doc.SaveToFile("sample.pdf");
            doc.Close();
            //Launching the Pdf file.
            System.Diagnostics.Process.Start("sample.pdf");
        }
    }
}  
Convert HTML to PDF with VB.NET:

Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports Spire.Pdf
Namespace HTML2PDF
         Class Program
                 <STAThread> _                 Private Shared Sub Main(args As String())
                          'Create a pdf document.
                          Dim doc As New PdfDocument()
                          Dim url As [String] = http://www.e-iceblue.com/
                          doc.LoadFromHTML(url, False, True, True)
                          'Save pdf file.
                          doc.SaveToFile("sample.pdf")
                          doc.Close()
                          'Launching the Pdf file.
                          System.Diagnostics.Process.Start("sample.pdf")
                 End Sub
         End Class
End Namespace


Preview





Besides converted from HTML, PDF can be converted by EXCEL, Word, Text, XML, Image and RTF. If you want to give it a try, you can Freely Download Spire. PDF


Source

4/09/2012

Set up Word Styles with C#, VB.NET

When we decorate our new house, we exert our utmost effort to choose furnishings to match house style. Besides, we also design to place every piece of furniture in the right position. Only both the house furnishings and their positions are suitably designed can the interior be gracefully decorated. By the same token, our word document is just like a house, only when we append the useful content and set up compatible content styles can our document look more distinctive and outstanding. Various word styles are available in the word processing program. Word styles allow you set up the format to combine the document and its information in the best way. Now let us learn how to set up word styles with C#, VB.NET in Spire. Doc when using Visual Studio. Of course, we should know what is Spire. Doc first.
Spire.Doc, as one important product of e-iceblue, is an MS word component. But Spire. Doc enables its users to perform a wide range of processing tasks directly without Microsoft Office Word installed in the computer. It can effectively generate, read, write and modify Word document for .NET and Silverlight. Besides, it supports C#, VB.NET, ASP.NET ASP.NET MVC and Silverlight as well as Word 97, Word 2003, Word 2007 and Word 2010.
In my prrocedure, I need to use Spire.Doc and Visual Studio to help me realize the task.

First, create the Word Styles project.
Open Visual Studio (2008 or later)—File—New Project—Visual C#—Windows Forms Application. Name Windows Forms Application Word Styles (if you need to create a Visual Basic project, Windows Forms Application, you can name the project Word Styles)—OK.

Second, add a button.
After building project Word Styles in Form 1, you need to add a button in Form1.

Third, add references.
Open Solution ExplorerClick project Add ReferenceFind "C:\Program Files\e-iceblue\Spire.Doc"the default folder which you installed the Spire Doc in )— Double-click the folder Bin.
If the target framework of the project
       Net 2.0, double-click folder NET2.0  
      or Net 3.5, double-click folder NET3.5
         or Net 4.0, double-click folder NET4.0
 Select assembly Spire Doc dll Click OK

Fourth, view the method.
After you create the project Word Styles, double-click “button1”, you can see the cold view and the following method has been added automatically:
C#
private void button1_Click(object sender, EventArgs e)

VB.NET    
Private Sub button1_Click(ByVal sender As Object,  ByVal e As EventArgs)  Handles button1.Click



Fifth, add the following codes to the top of the file:
C#
using Spire.Doc;
using Spire.Doc.Documents;
   
VB.NET    
Imports Spire.Doc
Imports
Spire.Doc.Documents



Sixth, add the following codes to the method.
C#
private void button1_Click(object sender, EventArgs e)
{
    //Create word document
    Document document = new Document();

    //Create a new secition
    Section section = document.AddSection();

    //Create a new paragraph
    Paragraph paragraph = section.AddParagraph();

    //Append Text
    paragraph.AppendText("Builtin Style:");

    foreach (BuiltinStyle builtinStyle in Enum.GetValues(typeof(BuiltinStyle)))
    {
        paragraph = section.AddParagraph();
        //Append Text
        paragraph.AppendText(builtinStyle.ToString());
        //Apply Style
        paragraph.ApplyStyle(builtinStyle);
    }

    //Save doc file.
    document.SaveToFile("Sample.doc",FileFormat.Doc);

    //Launching the MS Word file.
    WordDocViewer("Sample.doc");


}

private void WordDocViewer(string fileName)
{
    try
    {
        System.Diagnostics.Process.Start(fileName);
    }
    catch { }
}





VB.NET    
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
        'Create word document
        Dim document_Renamed As New Document()

        'Create a new secition
        Dim section_Renamed As Section = document_Renamed.AddSection()

        'Create a new paragraph
        Dim paragraph_Renamed As Paragraph = section_Renamed.AddParagraph()

        'Append Text
        paragraph_Renamed.AppendText("Builtin Style:")

        For Each builtinStyle_Renamed As BuiltinStyle In System.Enum.GetValues(GetType(BuiltinStyle))
               paragraph_Renamed = section_Renamed.AddParagraph()
               'Append Text
               paragraph_Renamed.AppendText(builtinStyle_Renamed.ToString())
               'Apply Style
               paragraph_Renamed.ApplyStyle(builtinStyle_Renamed)
        Next builtinStyle_Renamed

        'Save doc file.
        document_Renamed.SaveToFile("Sample.doc",FileFormat.Doc)

        'Launching the MS Word file.
        WordDocViewer("Sample.doc")


End Sub

Private Sub WordDocViewer(ByVal fileName As String)
        Try
               Process.Start(fileName)
        Catch
        End Try
End Sub



Finally, operate the project Word Styles.
In Solution Explorer, right-click the project Word StylesClick DebugStart new instance, you can see the opened window Form1Click button 1, you can see picture 7.1 shows itself:






Word Styles offer people diverse palette options which work with the main design. Through the setup of word styles, you can quickly and easily apply a set of formatting choices consistently in your document. Word Styles contains four big types: paragraph, character, list, and table. Paragraph styles are mostly used in people’s daily work. If we can make good use of paragraph styles, we may feel amazing about how much stressful work we escape when we work in a long document. Furthermore, our document will look more professional in a whole sight. In fact, the less work you do, the better your document will be! This is what word styles bring to us. But if you cannot use the word styles well, you will have a lot of troubles. So if you want to know more about the function of word styles in Spire. Doc, you can visite the Word Forum.


Source