C# 中实现导出Excel和打印(利用Excel)、预览等功能,用什么技术好?_百 ...
发布网友
发布时间:2024-01-12 16:58
我来回答
共2个回答
热心网友
时间:2024-08-05 19:59
自已写代码最好,
从SQL数据库把数据导出保存到本地
Private Sub WriteExcel()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim nn As Integer = 0
Irowcount = objDataSet.Tables("DataAnalyseVIEW").Rows.Count
Icolcount = objDataSet.Tables("DataAnalyseVIEW").Columns.Count
Try
xlApp = CreateObject("Excel.Application")
xlBook = xlApp.Workbooks.Add
xlSheet = xlBook.Worksheets(1)
xlSheet.Name = "DataAnalyse"
xlSheet.Cells(1, 1).Value = objDataSet.Tables("DataAnalyseVIEW").Columns(2).ColumnName().ToString()
xlSheet.Cells(1, 2).Value = objDataSet.Tables("SerialNumberTable").Rows(txtN)("SerialNumber").ToString()
xlSheet.Cells(2, 1).Value = objDataSet.Tables("DataAnalyseVIEW").Columns(3).ColumnName().ToString()
xlSheet.Cells(2, 2).Value = objDataSet.Tables("DataAnalyseVIEW").Rows(0)("Client").ToString()
xlSheet.Cells(3, 1).Value = objDataSet.Tables("DataAnalyseVIEW").Columns(5).ColumnName().ToString()
xlSheet.Cells(3, 2).Value = objDataSet.Tables("DataAnalyseVIEW").Rows(0)("Productor").ToString()
xlSheet.Cells(4, 1).Value = objDataSet.Tables("DataAnalyseVIEW").Columns(6).ColumnName().ToString()
xlSheet.Cells(4, 2).Value = objDataSet.Tables("DataAnalyseVIEW").Rows(0)("Model").ToString()
xlSheet.Cells(5, 1).Value = objDataSet.Tables("DataAnalyseVIEW").Columns(4).ColumnName().ToString()
xlSheet.Cells(5, 2).Value = objDataSet.Tables("DataAnalyseVIEW").Rows(0)("StationName").ToString()
xlSheet.Cells(6, 1).Value = objDataSet.Tables("DataAnalyseVIEW").Columns(7).ColumnName().ToString()
xlSheet.Cells(6, 2).Value = objDataSet.Tables("DataAnalyseVIEW").Rows(0)("DataTime").ToString()
xlSheet.Cells(7, 1).Value = objDataSet.Tables("DataAnalyseVIEW").Columns(8).ColumnName().ToString()
xlSheet.Cells(7, 2).Value = objDataSet.Tables("DataAnalyseVIEW").Rows(0)("status").ToString()
xlSheet.Cells(8, 1).Value = "Result Begin"
Progressbar1.Step = 1
Progressbar1.Value = 1
Progressbar1.Visible = True
For i = 0 To Icolcount - 1
If i < 2 Or i > 7 Then
nn = nn + 1
xlSheet.Cells(9, nn).Value = objDataSet.Tables("DataAnalyseVIEW").Columns(i).ColumnName().ToString
End If
Next
这是VB.net代码,可以直接转为C#.net
详细代码:http://hi.baidu.com/jonesvale/blog/item/3134ff1ecebdfc64f724e44b.html
热心网友
时间:2024-08-05 19:54
需要那么复杂么?直接使用Excel相关的函数操作不就好了?至于导出需要看你的格式需求再确定