代码导出的excel表,填充了颜色样式的单元格,“有效期至” 无法改成日期格式,“生产日期” 不受影响,整了半天,想不出原因,谢谢;
此主题相关图片如下:捕获.png
'生成excel表
Dim bm As String = "近效期库存预警" & Date.Today.Year & Date.Today.Month & Date.Today.Day '设置表名
Dim bm1 As String = "F:\狐表\计划任务\临时表\" & bm & ".xls" '设置表储存位置
Dim bo As new XLS.Book
Dim sh As XLS.Sheet = bo.Sheets(0)
'填充字段及格式
Dim st As xls.style = bo.NewStyle '定义一个EXCEL样式
st.BackColor = Color.Red '背景颜色为红色
Dim st1 As xls.style = bo.NewStyle '定义一个EXCEL样式
st1.BackColor = Color.yellow '背景颜色为黄色
Dim st2 As xls.style = bo.newstyle
st2.Format = "yyyy-MM-dd"
For c As Integer = 0 To dt.DataCols.Count - 1
sh(0,c).Value = dt.DataCols(c).Name
For c1 As Integer = 0 To dt.DataRows.Count - 1
sh(c1 + 1 ,c).Value = dt.DataRows(c1)(dt.DataCols(c).Name)
If dt.DataRows(c1)("有效期天数") <= 30 Then
For c2 As Integer = 0 To sh.Cols.Count - 1
sh(c1 + 1,c2).Style = st '设置样式
'If sh(0,c2).Value = "有效期至" OrElse sh(0,c2).Value = "生产日期" Then
'sh(0,c2).Style = st2 '设置列格式
'End If
Next
ElseIf dt.DataRows(c1)("有效期天数") > 30 AndAlso dt.DataRows(c1)("有效期天数") <= 60 Then
For c2 As Integer = 0 To sh.Cols.Count - 1
sh(c1 + 1,c2).Style = st1 '设置样式
'If sh(0,c2).Value = "有效期至" OrElse sh(0,c2).Value = "生产日期" Then
'sh(0,c2).Style = st2 '设置列格式
'End If
Next
End If
Next
Next
For c2 As Integer = 0 To sh.Cols.Count - 1
If sh(0,c2).Value = "生产日期" OrElse sh(0,c2).Value = "有效期至" Then
sh.Cols(c2).Style = st2 '设置列格式
End If
Next
sh.Name = bm '修改工作表名称
bo.Save(bm1) '保存表并命名