请问大家WINCC用户归档导出来的数据怎么修改成EXECL格式的文件?能把分号替换吗?然后和EXECL一样用单元格显示出来,谢谢!
最佳答案
Dim UA,col,row,rows
Dim xlapp,objsheet
Dim i,j,k,m,n,filename
Set UA=ScreenItems("UA")
Set rows=UA.GetRowCollection
m=rows.Count
n=UA.ColumnCount
If m>1 Then ''如果用户归档控件有记录
Set xlapp=CreateObject("Excel.Application")
xlapp.visible=False
xlapp.workbooks.add
Set objsheet=xlapp.worksheets(1)
For k=1 To n
ua.ColumnIndex=k-1
objsheet.cells(3,k)=ua.ColumnCaption ''字段名称
Next
objsheet.cells(1,1)="生产报表"
For i=1 To m
For j= 1 To n
objsheet.cells(i+3,j)=ua.GetRow(i).celltext(j)
Next
Next
''以下代码处理日期时间数据格式以及表格边框线、标题合并单元格等排版
objsheet.range("a1:p1").mergecells=True
objsheet.range("b2:p2").mergecells=True
objsheet.range("a1").ColumnWidth =11 ''列宽
objsheet.range("b1").ColumnWidth =8
objsheet.range("c1").ColumnWidth =8
objsheet.range("d1").ColumnWidth =8
objsheet.range("e1").ColumnWidth =8
objsheet.range("f1").ColumnWidth =11
objsheet.range("g1").ColumnWidth =8
objsheet.range("h1").ColumnWidth =8
objsheet.range("i1").ColumnWidth =11
objsheet.range("j1").ColumnWidth =8
objsheet.range("k1").ColumnWidth =8
objsheet.range("l1").ColumnWidth =8
objsheet.range("m1").ColumnWidth =11
objsheet.range("n1").ColumnWidth =11
objsheet.range("o1").ColumnWidth =11
objsheet.range("p1").ColumnWidth =11
Dim myDy
Dim Seldate
Seldate=HMIRuntime.Tags("myDate").Read
myDy=CStr(Year(Seldate)) +"-" +CStr(Month(Seldate))+"-"+CStr(Day(Seldate))
objsheet.cells(2,1)="报表日期:"
''objsheet.cells(2,2)=Year(Now) & "年" & Month(Now) & "月" & Day(Now) & "日"
objsheet.cells(2,2)=myDy
objsheet.cells(1,1).HorizontalAlignment = 3''居中
objsheet.cells(2,2).HorizontalAlignment = 2
objsheet.range("a1:p" & CStr(3+m)).borders(1).linestyle=9
objsheet.range("a1:p" & CStr(3+m)).borders(1).weight=2
objsheet.range("a1:p" & CStr(3+m)).borders(2).linestyle=9
objsheet.range("a1:p" & CStr(3+m)).borders(2).weight=2
objsheet.range("a1:p" & CStr(3+m)).borders(3).linestyle=9
objsheet.range("a1:p" & CStr(3+m)).borders(3).weight=2
objsheet.range("a1:p" & CStr(3+m)).borders(4).linestyle=9
objsheet.range("a1:p" & CStr(3+m)).borders(4).weight=2
''保存文件
filename= "c:\" & mydy & " 报表 " & Year(Now) & "-" & Month(Now) & "-" & Day(Now) & " " & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & " 生成.xlsx"
xlapp.Activeworkbook.saveas (filename)
xlapp.workbooks.close
xlapp.quit
Msgbox "成功导出到C:\"
Else
Msgbox "用户归档没有记录"
End If
提问者对于答案的评价:
谢谢!
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc315088.html