更改Excel格式将文件转换为疯狂的大小

我只是使用vba代码更改表格的格式,文件变得非常大,增加了大约200 MB。 如果我使用Excel接口来做这件事情,但是我不想使用这些代码。

Function ReturnName(ByVal num As Integer) As String ReturnName = Split(Cells(, num).Address, "$")(1) End Function lcol = ws1.Cells(1, ws1.Columns.Count).End(xlToLeft).Column For i = 1 To lcol If (ws1.Cells(4, i) = "Date") Then ws1.Range(ReturnName(i) & "5" & ":" & ReturnName(i) & "1000").NumberFormat = "yyyy-mm-dd" Else ws1.Range(ReturnName(i) & "5" & ":" & ReturnName(i) & "1000").NumberFormat = "0" End If Next i 

试试这个例子:

 ws1.Range(ReturnName(i) & "5").EntireColumn.NumberFormat = "yyyy-mm-dd"