Thursday, 04 August 2011 03:01

Export Data from Listview to XML

Why Export Listview to Office OpenXML?

Office OpenXML has its own advantages. Office OpenXML, or Extensible Markup Language is a set of rules for encoding documents in machine-readable form. The real power of Office OpenXML comes from the fact that with Office OpenXML, not only can you define your own set of tags, but the rules specified by those tags need not be limited to formatting rules. And the most benefit of Office OpenXML is that because you are writing your own markup language, you are not restricted to a limited set of tags defined by proprietary vendors. Furthermore, Office OpenXML allows you to define all sorts of tags with all sorts of rules, such as tags representing business rules or tags representing data description or data relationships.

How to Export Listview to Office OpenXML?

As a professional and powerful .NET component suit for data exporting, Spire.DataExport for .NET can export data from Database to MS Excel,MS Word, HTML, Office OpenXML, PDF, MS Access, DBF, SQL Script, SYLK, DIF, CSV ,MS Clipboard format and of course enable to export ListView to Office OpenXML.

Spire.DataExport for .NET offers an easy solution on Exporting listview to Office OpenXML. Download Spire.DataExport (or Spire.Office) with .NET framework 2.0 (or above) together and use the code below to Export Listview to Office OpenXML:

[C#]
this.xmlExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
			this.xmlExport1.DataFormats.CultureName = "zh-CN";
			this.xmlExport1.DataFormats.Currency = "c";
			this.xmlExport1.DataFormats.DateTime = "yyyy-M-d H:mm";
			this.xmlExport1.DataFormats.Float = "g";
			this.xmlExport1.DataFormats.Integer = "g";
			this.xmlExport1.DataFormats.Time = "H:mm";
			this.xmlExport1.FileName = "sample.xml";
            this.xmlExport1.DataSource = Common.ExportSource.ListView;
            this.xmlExport1.ListView = this.listView1;
oleDbConnection1.Open();
try{
xmlExport1.SaveToFile();
}
Finally
{
oleDbConnection1.Close();

}
[VB.NET]
Me.xmlExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView
            Me.xmlExport1.DataFormats.CultureName = "zh-CN"
            Me.xmlExport1.DataFormats.Currency = "c"
            Me.xmlExport1.DataFormats.DateTime = "yyyy-M-d H:mm"
            Me.xmlExport1.DataFormats.Float = "g"
            Me.xmlExport1.DataFormats.Integer = "g"
            Me.xmlExport1.DataFormats.Time = "H:mm"
            Me.xmlExport1.FileName = "sample.xml"
            Me.xmlExport1.DataSource = Common.ExportSource.ListView
            Me.xmlExport1.ListView = Me.listView1
oleDbConnection1.Open()
            Try
                 xmlExport1.SaveToFile()
Finally
                Me.oleDbConnection1.Close()
            End Try
Published in ListView Export
Monday, 24 January 2011 09:49

Save Excel Document in C#, VB.NET

Automation of an Excel file allows us to doing various operations in C#/VB.NET. Any loss in these operations may result in unexpected negative consequences for developers and the clients of the developers. That means we must find a solution that enables us to Save Excel with no loss in quality of our operations. This section will demonstrate how to fast save Excel file with perfect performance as directly operations in Excel files.

Spire.Xls for .NET is a professional component that enables developers directly manages Excel operation regardless whether Microsoft Excel is installed on or not. With Spire.Xls for .NET, we can save Excel to what we want it to be. Any kind of trial and evaluation on Spire.Xls for .NET is always welcomed; so now please feel free to download Spire.Xls for .NET and then follow our guide to save perfect Excel or try other function of Spire.Xls for .NET.

Spire.Xls for .NET allows us to create a new Excel file, write data in to it, edit the input data and then save Excel file.

[C#]
using Spire.Xls;
namespace Excel_save
{
   class Program
    {
        static void Main(string[] args)
        {
           //Create a new workbook
            Workbook workbook = new Workbook();
           //Initialize worksheet        
            Worksheet sheet = workbook.Worksheets[0];           
           //Append text
            sheet.Range["A1"].Text = "Demo: Save Excel in .NET";
           //Save it as Excel file
            workbook.SaveToFile("Sample.xls",ExcelVersion.Version97to2003);
           //Launch the file
           System.Diagnostics.Process.Start(workbook.FileName);
        }
    }
}
[VB.NET]
Imports Spire.Xls
Namespace Excel_save
	Class Program
		Private Shared Sub Main(args As String())
			'Create a new workbook
			Dim workbook As New Workbook()
			'Initialize worksheet        
			Dim sheet As Worksheet = workbook.Worksheets(0)
			'Append text
			sheet.Range("A1").Text = "Demo: Save Excel in .NET"
			'Save it as Excel file
			workbook.SaveToFile("Sample.xls",ExcelVersion.Version97to2003)
			'Launch the file
			System.Diagnostics.Process.Start(workbook.FileName)
		End Sub
	End Class
End Namespace
Published in Document Operation

Basic Knowledge about Office OpenXML

When talking about Office OpenXML, we may think of HTML. Actually, Office OpenXML is similar to HTML both are tag-based languages. The difference between Office OpenXML and HTML is that the tags which Office OpenXML uses are not predefined. If we want to create own tags within Office OpenXML, we need to follow a few rules.

Firstly, only one root element is contained in Office OpenXML document. The root element is often taken as document element and appears after the prolog section. Besides, all the Office OpenXML elements should contain end tags. Both start and end tag should be identical. Also, the elements can’t overlap. What’s more, all attribute values must use quotation marks and we can’t use some special characters within the text. After following the rules, the Office OpenXML document will be well formatted.

Use C# and VB.NET Convert Doc to Office OpenXML via Spire.Doc

Spire.Doc (Spire.Office) presents you an easy way to convert Doc to Office OpenXML. In this way, we can convert an exist Word doc file to Office OpenXML format with a few clicks. Now, just follow the simple steps.

Step 1: Create Project

Download Spire.Doc and install on system. Create a project through Visual Studio and add Spire.Doc DLL as reference.

Note: Please make sure Spire.Doc and Visual Studio are correctly installed on system

Step 2: Load Word Doc File

Load local Word doc file which we need to convert to Office OpenXML format. The following code can help us load it.

Document document = new Document();
document.LoadFromFile(@"D:\Sample.doc");

Step 3: Convert Doc to Office OpenXML

Spire.Doc supports convert Word Doc files to most of popular file formats such as PDF, HTML, Office OpenXML, EPub, RTF, Dot, Text, etc. Now, use the code below to convert Word to Office OpenXML.

document.SaveToFile("Sample.xml", FileFormat.Xml);

Step 4: Full Code

Now, write the full code into your project and press F5 to start the program.

[C#]
using System;
using System.Windows.Forms;
using Spire.Doc;
using Spire.Doc.Documents;

namespace to XML
{
    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");

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

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

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

    }
}
[VB.NET]
Imports System
Imports System.Windows.Forms
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace to XML
	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")

			'Save doc file.
			document.SaveToFile("Sample.xml", FileFormat.Xml);

			'Launching the MS Word file.
			WordDocViewer("Sample.xml")
		End Sub

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

	End Class
End Namespace

After running the demo, you may find an Office OpenXML document launched on your browser:

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 Conversion
Sunday, 01 August 2010 18:38

Data Export XML in C#, VB.NET

This sample demonstrates how to export data table into xml file.

Published in Demo
Saturday, 03 July 2010 14:15

EXCEL XLSX in C#, VB.NET

 

The sample demonstrates how to load excel 2007 format file.

XLSX.gif

Published in Excel2007
Saturday, 03 July 2010 10:46

Excel XML in C#, VB.NET

 

The sample demonstrates how to write an excel workbook to an XML file.

WriteXML.gif

Published in XML