Dim dt As Table = Tables("窗口3_Table1")
Dim nms() As String = {"客户编号", "面料名称", "色号", "颜色", "数量", "交货日期", "交货单位"} '要导出的列名
Dim caps() As String = {"客户编号", "面料名称", "色号", "颜色", "数量", "交货日期", "交货单位"} '对应的列标题
Dim szs() As Integer = {70, 130, 60, 65, 60, 120, 120} '对应的列宽
Dim Book As New XLS.Book '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Sheet(0, 0).Value = "交货明细"
Dim st1 As XLS.Style = Book.NewStyle
st1.BorderTop = XLS.LineStyleEnum.Thin
st1.BorderBottom = XLS.LineStyleEnum.Thin
st1.BorderLeft = XLS.LineStyleEnum.Thin
st1.BorderRight = XLS.LineStyleEnum.Thin
st1.BorderColorTop = Color.Black
st1.BorderColorBottom = Color.Black
st1.BorderColorLeft = Color.Black
st1.BorderColorRight = Color.Black
Sheet.Rows(0).Height = 40
Sheet.MergeCell(0, 0, 1, nms.length)
Sheet(0, 0).Style = st1
st1.AlignHorz = XLS.AlignHorzEnum.Center
st1.AlignVert = XLS.AlignVertEnum.Center
For c1 As Integer = 0 To nms.length - 1
Sheet(1, c1).Style = st1
Next
For r As Integer = 0 To dt.Rows.Count - 1
For c As Integer = 0 To nms.length - 1
If dt.Cols(nms(c)).IsDate = False Then
Sheet(r + 2, c).Style = St1
End If
Next
Next
For c As Integer = 0 To nms.length - 1
Sheet(1, c).Value = caps(c) '指定列标题
Sheet.Cols(c).Width = szs(c) '指定列宽
Sheet.Rows(1).Height = 30
Next
For c As Integer = 0 To nms.length - 1
For r As Integer = 0 To dt.Rows.Count - 1 '填入数据
Sheet(r + 2, c).Value = dt.rows(r)(nms(c))
Sheet.Rows(r + 2).Height = 30
Next
Next
Dim st2 As XLS.Style = Book.NewStyle '日期列的显示格式
st2.BorderTop = XLS.LineStyleEnum.Thin
st2.BorderBottom = XLS.LineStyleEnum.Thin
st2.BorderLeft = XLS.LineStyleEnum.Thin
st2.BorderRight = XLS.LineStyleEnum.Thin
st2.BorderColorTop = Color.Black
st2.BorderColorBottom = Color.Black
st2.BorderColorLeft = Color.Black
st2.BorderColorRight = Color.Black
st2.AlignHorz = XLS.AlignHorzEnum.Center
st2.AlignVert = XLS.AlignVertEnum.Center
st2.Format = "yyyy-MM-dd"
For c As Integer = 0 To nms.length - 1
For r As Integer = 0 To dt.Rows.Count - 1 '填入数据
If dt.Cols(nms(c)).IsDate Then '如果是日期列
Sheet(r + 2, c).Style = st2 '设置显示格式
End If
Next
Next
Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter = "Excel文件|*.xlsx" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then
Book.Save(dlg.FileName)
Dim Proc As New Process
Proc.File = dlg.FileName
Proc.Start()
End If
现在我需要导出的EXCEL表格自动合并相同值的行,代码怎么写?,如下图:
此主题相关图片如下:02.jpg