老师、代码如下:
Dim dt As Table = Tables("整车质量报表_table1")
Dim du As Table = Tables("整车质量报表_table2")
Dim nms() As String = {"日期","编号","代号","底盘号","发动机号","序号","不良描述","部门","检验岗","判定","检验","处罚","操作人","考核","预防措施"} '要导出的列名
Dim caps() As String = {"日期","台数","代号","底盘号","发动机号","序号","不良描述","部门","检验岗","判定","检验员","考核","操作人","考核","原因分析及预防措施"} '对应的列标题
Dim szs() As Integer = {90,55,50,85,100,45,350,40,60,60,60,40,70,40,550} '对应的列宽
Dim Book As New XLS.Book '定义一个Excel工作簿
Book.Sheets.Add( status2 ) '增加一个工作表
Book.Sheets.Add( status3 ) '增加一个工作表
Dim Sheet As XLS.Sheet = Book.Sheets ( status2 ) '引用工作簿的第一个工作表
Dim Sheet1 As XLS.Sheet = Book.Sheets( status3 ) '引用工作簿的第二个工作表
Dim Style As XLS.Style = Book.NewStyle() '定义新样式'样式为:有网格线,内容居中
Style.BorderTop = XLS.LineStyleEnum.Thin
Style.BorderBottom = XLS.LineStyleEnum.Thin
Style.BorderLeft = XLS.LineStyleEnum.Thin
Style.BorderRight = XLS.LineStyleEnum.Thin
Style.BorderColorTop = Color.Black
Style.BorderColorBottom = Color.Black
Style.BorderColorLeft = Color.Black
Style.BorderColorRight = Color.Black
Style.AlignHorz = XLS.AlignHorzEnum.Center '水平居中
Style.AlignVert = XLS.AlignVertEnum.Center '垂直居中
。。。。。省略了
For c As Integer = 0 To nms.length -1
If dt.cols(nms(c)).isdate Then
If dt.rows(r)(nms(c)) = Nothing Then '依据条件调用日期数据区域样式
Sheet(r + 3, c).Style = bt
Else
Sheet(r + 3, c).Style = st
End If
Sheet(r + 3, c).Value = dt.rows(r)(nms(c)) '填入日期数据
End If
'部分区域单元格调用样式命令
Sheet(r + 3, c + 1).Style = Style '从第三行第二列开始调用新样式:居中,带边框
Sheet(r + 3, 6).Style = ct '从第三行第14列开始调用新样式:居左,带边框
Sheet(r + 3, 14).Style = ct '从第三行第15列开始调用新样式:居左,带边框
Sheet(r + 3, 15).Style = bt '从第三行第16列开始调用新样式:居左,无边框
Sheet(r + 3, c).Value = dt.rows(r)(nms(c)) '填入数据
Next
。。。。省略了
Book.Sheets.RemoveAt(0) '删除第一个工作表
Book.Save( status4 ) ‘调用设置的变量命名保存的表
Dim Proc As New Process
Proc.File = status4 ’打开表
Proc.Start()
老师你费心看看!