首页 热点资讯 义务教育 高等教育 出国留学 考研考公

C# 中实现导出Excel和打印(利用Excel)、预览等功能,用什么技术好?

发布网友 发布时间:2024-12-20 21:32

我来回答

2个回答

热心网友 时间:4分钟前

自已写代码最好,
从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/3134ff1ecebdfcf724e44b.html

热心网友 时间:6分钟前

需要那么复杂么?直接使用Excel相关的函数操作不就好了?至于导出需要看你的格式需求再确定

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com