UltraWinGrid导出EXCEL的一些技术文档
来源:互联网 发布:trackpad2 windows 编辑:程序博客网 时间:2024/05/06 13:45
DATAGRID 导出EXCEL的方法
许多朋友,在做DATAGRID中的数据导成EXCEL的时候,都碰到问题,需要些较多的代码,现在,大家可以用UltraWinGrid, UltraGridExcelExporter来实现EXCEL导出。
首先,分别拉一个UltraWinGrid, UltraGridExcelExporte控件到项目中,配置好UltraWinGrid数据源[这里省略了],然后就是导出数据:
//新建一个工作簿
Workbook myWorkbook = new Workbook();
Worksheet myWorksheep = myWorkbook.Worksheets.Add("新建工作表");
//设置横向打印
myWorksheep.PrintOptions.Orientation = Infragistics.Excel.Orientation.Landscape;
//设置页眉
myWorksheep.PrintOptions.Header = "&L &/r/n 表Ⅰ" +"&C&13报表页眉" +"&R&/r/n单位:亩 第&P页共&N页";
//设置页脚
myWorksheep.PrintOptions.Footer = "&L填表人:xxx 填表日期&D &R填表人:xxx 填表日期&D ";
//导出EXCEL
this.ExproterExel.Export(this.ultraGridmj,myWorksheep);
BIFF8Writer.WriteWorkbookToFile(myWorkbook, this.savef.FileName.ToString());
以下是有关UltraWinGrid导出EXCEL的一些技术文档
Exports the passed in ultragrid to the specified worksheet.
-----------------------------------------------------------------------------------------------------------------
Gets or sets the header for each page of the printed worksheet.
Syntax
Public Property Header As String
public string Header {get; set;}
Return Value
The header for each page of the worksheet.Remarks
The '&' character in the header and footer is a special character. Depending on what is after it, the formatting of the text can be controlled or dynamic text can be inserted. Below is a list of the available commands:
The header or footer string could look like this: &L&"Arial,Bold"&D&CPage &P of &N on &A&R&14&F.
Example
Imports Infragistics.Excel
' Create a workbook with a worksheet
Dim workbook As New Workbook()
Dim worksheet1 As Worksheet = workbook.Worksheets.Add("Sheet1")
' The contents of each printed page of the workshete should be centered vertically
' and horizontally
worksheet1.PrintOptions.CenterHorizontally = True
worksheet1.PrintOptions.CenterVertically = True
' Each page should be printed with a landscape orientation
worksheet1.PrintOptions.Orientation = Infragistics.Excel.Orientation.Landscape
' Modify the margins of each page of the worksheet
worksheet1.PrintOptions.BottomMargin = 1
worksheet1.PrintOptions.TopMargin = 1
worksheet1.PrintOptions.LeftMargin = 1
worksheet1.PrintOptions.RightMargin = 1
worksheet1.PrintOptions.HeaderMargin = 0.5
worksheet1.PrintOptions.FooterMargin = 0.5
' Show the current date centered at the top of each page
worksheet1.PrintOptions.Header = "&C&D"
' Show "Page <page number> of <number of pages>" on the bottom right of each page
worksheet1.PrintOptions.Footer = "&RPage &P of &N"
' Print gridlines and row and column headers on each page
worksheet1.PrintOptions.PrintRowAndColumnHeaders = True
worksheet1.PrintOptions.PrintGridlines = True
' Print cell notes at the end of the worksheet
worksheet1.PrintOptions.PrintNotes = PrintNotes.PrintAtEndOfSheet
' Print all cell errors as "#N/A"
worksheet1.PrintOptions.PrintErrors = PrintErrors.PrintAsNA
' Print in black and white and in draft quality
worksheet1.PrintOptions.PrintInBlackAndWhite = True
worksheet1.PrintOptions.DraftQuality = True
using System.Windows.Forms;
using Infragistics.Excel;
// Create a workbook with a worksheet
Workbook workbook = new Workbook();
Worksheet worksheet1 = workbook.Worksheets.Add( "Sheet1" );
// The contents of each printed page of the workshete should be centered vertically
// and horizontally
worksheet1.PrintOptions.CenterHorizontally = true;
worksheet1.PrintOptions.CenterVertically = true;
// Each page should be printed with a landscape orientation
worksheet1.PrintOptions.Orientation = Infragistics.Excel.Orientation.Landscape;
// Modify the margins of each page of the worksheet
worksheet1.PrintOptions.BottomMargin = 1;
worksheet1.PrintOptions.TopMargin = 1;
worksheet1.PrintOptions.LeftMargin = 1;
worksheet1.PrintOptions.RightMargin = 1;
worksheet1.PrintOptions.HeaderMargin = 0.5;
worksheet1.PrintOptions.FooterMargin = 0.5;
// Show the current date centered at the top of each page
worksheet1.PrintOptions.Header = "&C&D";
// Show "Page <page number> of <number of pages>" on the bottom right of each page
worksheet1.PrintOptions.Footer = "&RPage &P of &N";
// Print gridlines and row and column headers on each page
worksheet1.PrintOptions.PrintRowAndColumnHeaders = true;
worksheet1.PrintOptions.PrintGridlines = true;
// Print cell notes at the end of the worksheet
worksheet1.PrintOptions.PrintNotes = PrintNotes.PrintAtEndOfSheet;
// Print all cell errors as "#N/A"
worksheet1.PrintOptions.PrintErrors = PrintErrors.PrintAsNA;
// Print in black and white and in draft quality
worksheet1.PrintOptions.PrintInBlackAndWhite = true;
worksheet1.PrintOptions.DraftQuality = true;
See Also
Reference
PrintOptions ClassPrintOptions Members
Footer Property
HeaderMargin Property
Syntax
Public Overloads Function Export( _ ByVal grid As UltraGrid, _ ByVal worksheet As Worksheet _) As Workbook
public Workbook Export( UltraGrid grid, Worksheet worksheet)
Parameters
- grid
- Grid to export.
- worksheet
- Destination Worksheet.
Return Value
Parent workbook of passed in worksheet.
Example
private void button2_Click(objectsender, System.EventArgs e)
{
// overload 1
this.MyGridExporter.Export(this.ultraGrid1,"Test1.xls");
}
private void button3_Click(objectsender, System.EventArgs e)
{
// overload 2
Workbook wb1 = this.MyGridExporter.Export(this.ultraGrid1);
BIFF8Writer.WriteWorkbookToFile(wb1, "Test2.xls");
Workbook wb2 = new Workbook();
// overload 3
this.MyGridExporter.Export(this.ultraGrid1, wb2);
Worksheet secondWS = wb2.Worksheets.Add("SecondSheet");
// overload 4
this.MyGridExporter.Export(this.ultraGrid1, secondWS);
BIFF8Writer.WriteWorkbookToFile(wb2, "Test3.xls");
Workbook wb3 = new Workbook();
// overload 5
this.MyGridExporter.Export(this.ultraGrid1, wb3, 1, 2);
Worksheet someWS = wb3.Worksheets.Add("SomeSheet");
// overload 6
this.MyGridExporter.Export(this.ultraGrid1, someWS, 2, 3);
BIFF8Writer.WriteWorkbookToFile(wb3, "Test4.xls");
}
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' overload 1
Me.MyGridExporter.Export(Me.UltraGrid1, "Test1.xls")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim wb1, wb2, wb3 As Workbook
Dim secondWS, someWS As Worksheet
' overload 2
wb1 = Me.MyGridExporter.Export(Me.UltraGrid1)
BIFF8Writer.WriteWorkbookToFile(wb1, "Test2.xls")
wb2 = New Workbook()
' overload 3
Me.MyGridExporter.Export(Me.UltraGrid1, wb2)
secondWS = wb2.Worksheets.Add("SecondSheet")
' overload 4
Me.MyGridExporter.Export(Me.UltraGrid1, secondWS)
BIFF8Writer.WriteWorkbookToFile(wb2, "Test3.xls")
wb3 = New Workbook()
' overload 5
Me.MyGridExporter.Export(Me.UltraGrid1, wb3, 1, 2)
someWS = wb3.Worksheets.Add("SomeSheet")
' overload 6
Me.MyGridExporter.Export(Me.UltraGrid1, someWS, 2, 3)
BIFF8Writer.WriteWorkbookToFile(wb3, "Test4.xls")
End Sub
转自:http://blog.csdn.net/guanzg/article/details/3876194
- UltraWinGrid导出EXCEL的一些技术文档
- thinkphp 导出Excel文档,导入Excel文档;PHPExcel的使用
- FarPoint导出excel文档
- JSP导出Excel文档
- Struts 导出 Excel 文档
- 选择性导出Excel文档
- POI导出Excel文档
- POI导出EXCEL文档
- java导出Excel文档
- extjs导出Excel文档
- Vertx_web导出excel文档
- 导出excel 文档1
- 导出excel文档2
- 导出excel文档
- POI 导出Excel文档
- DataGrid导出Excel遇到的一些问题
- jxl导出excel的一些方法
- dorado导出excel的一些问题
- Linux设备驱动之——I2C总线
- xcode变异错误“ "_OBJC_CLASS_$_Possession", referenced from:”
- 从bundle文件包中加载数据
- html5 svg 中元素点击事件添加
- Cocos2d-x-CCSpriteBatchNode
- UltraWinGrid导出EXCEL的一些技术文档
- Django项目13
- cocos2d-x学习笔记14:粒子系统1:简介&工具使用
- Boost多线程编程
- 嵌入式linux入门学习内容指南
- 史上最全android分辨率
- 嵌入式软件开发下的数据积累
- 网络存储器十大常用功能介绍
- Java Socket重要参数讲解