在一个服装销售软件中,要将每天的销售额通过发邮件的形式提交到老板那里.
于是:1,提取每天销售及退货情况.
2,自动导出为excel文件
3.以导出的excel为附件进行邮件群发
关键代码如下:
导出为excel文件
Public Sub exportExcel(ByVal dgv As DataGridView)
Try
If dgv.RowCount = 0 Then
MessageBox.Show("列表中无数据,导出数据失败", "提示")
Return
End If
'总列数
Dim columnCount As Integer = dgv.Columns.Count
'创建Excel对象
Dim excelApp As Microsoft.Office.Interop.Excel._Application = New ApplicationClass()
'新建工作簿
Dim workBook As Microsoft.Office.Interop.Excel._Workbook = excelApp.Workbooks.Add(True)
'新建工作表
Dim worksheet As Microsoft.Office.Interop.Excel._Worksheet = TryCast(workBook.ActiveSheet, Microsoft.Office.Interop.Excel._Worksheet)
'设置标题
Dim titleRange As Microsoft.Office.Interop.Excel.Range = worksheet.Range(worksheet.Cells(1, 1), worksheet.Cells(1, columnCount))
'选取单元格
titleRange.Merge(True)
'合并单元格
titleRange.Value2 = "欧榜服饰(" & SPName & ")"
'设置单元格内容
titleRange.Font.Name = "黑体"
'设置字体
'titleRange.Font.Color = Color.Red;//设置字体颜色
titleRange.Font.Size = 20
'设置字体大小
titleRange.Font.Bold = True
'字体加粗
titleRange.HorizontalAlignment = XlHAlign.xlHAlignCenter
'水平居中
titleRange.VerticalAlignment = XlVAlign.xlVAlignCenter
'垂直居中
&#