excel表格的列数,最大是256列,超过是不行的。
要用vba处理,大致代码如下,没看懂你到底要实现什么,细节自己调整
Dim App As New MSExcel.Application
Dim Wb As MSExcel.Workbook = App.WorkBooks.Add
Dim ws = Wb.WorkSheets(1)
ws.name = "test"
Dim dict As new Dictionary(of String,Integer)
Dim lst As List(Of String) = DataTables("日库存表").GetValues("英文名称")
Dim zimu As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim i As Integer = 0
Dim idx As Integer
Dim Formula As String = "="
Dim k As Integer
Dim km As Integer
For i = 0 To lst.Count - 1
idx = i*7+1
k = Math.Floor((idx+2) / 26) - 1
km = (idx+2) Mod 26
'Output.Show("k=" & k & ", km=" & km)
If k< 0 Then
Formula &= zimu(km) & "{0}+"
Else
Formula &= zimu(k) & zimu(km) & "{0}+"
End If
k = Math.Floor((idx+3) / 26) - 1
km = (idx+3) Mod 26
If k< 0 Then
Formula &= zimu(km) & "{0}+"
Else
Formula &= zimu(k) & zimu(km) & "{0}+"
End If
dict.Add(lst(i),idx)
ws.cells(0+1,idx+1).Value = lst(i)
ws.cells(1+1,idx+1+1).Value = "出入库"
ws.cells(1+1,idx+1+1).Value = "库存"
ws.cells(1+1,idx+2+1).Value = "装卸费"
ws.cells(1+1,idx+3+1).Value = "堆存费"
ws.cells(1+1,idx+4+1).Value = "拆箱费"
ws.cells(1+1,idx+5+1).Value = "出签费"
ws.cells(1+1,idx+6+1).Value = "备注"
'Dim Rg As MSExcel.Range = Ws.Range(ws.cells(1,idx+1).Address & ":" & ws.cells(1,idx+1+7).Address)
'App.DisplayAlerts = False '加上此行可禁止弹出合并前的提示
'Rg.Merge
'Sheet.MergeCell(0,idx,1,7)
Next
idx = i*7+1
k = Math.Floor(idx / 26) - 1
km = idx Mod 26
If k< 0 Then
Formula &= zimu(km) & "{0}+"
Else
Formula &= zimu(k) & zimu(km) & "{0}+"
End If
k = Math.Floor((idx+1) / 26) - 1
km = (idx+1) Mod 26
If k< 0 Then
Formula &= zimu(km) & "{0}+"
Else
Formula &= zimu(k) & zimu(km) & "{0}+"
End If
k = Math.Floor((idx+2) / 26) - 1
km = (idx+2) Mod 26
If k< 0 Then
Formula &= zimu(km) & "{0}+"
Else
Formula &= zimu(k) & zimu(km) & "{0}+"
End If
ws.cells(0+1,idx+1).Value = "装卸费"
Ws.Range(ws.cells(1,idx+1).Address & ":" & ws.cells(2,idx+1).Address).Merge
'Sheet.MergeCell(0,idx,2,1)
ws.cells(0+1,idx+1+1).Value = "堆存费"
Ws.Range(ws.cells(1,idx+2).Address & ":" & ws.cells(2,idx+2).Address).Merge
'Sheet.MergeCell(0,idx+1,2,1)
ws.cells(0+1,idx+2+1).Value = "拆箱费"
Ws.Range(ws.cells(1,idx+3).Address & ":" & ws.cells(2,idx+3).Address).Merge
'Sheet.MergeCell(0,idx+2,2,1)
ws.cells(0+1,idx+3+1).Value = "出签费"
Ws.Range(ws.cells(1,idx+4).Address & ":" & ws.cells(2,idx+4).Address).Merge
'Sheet.MergeCell(0,idx+2,2,1)
ws.cells(0+1,idx+4+1).Value = "仓储合计"
Ws.Range(ws.cells(1,idx+5).Address & ":" & ws.cells(2,idx+5).Address).Merge
'Sheet.MergeCell(0,idx+3,2,1)
Tables("日库存表").Sort = "日期"
Dim idx2 = 2
Formula = Formula.TrimEnd("+")
'Output.Show(Formula)
For Each r As Row In Tables("日库存表").Rows
ws.cells(idx2+1,0+1).Value = r("日期")
Dim j As Integer = dict(r("英文名称"))
ws.cells(idx2+1,j+1).Value = r("出入库")
ws.cells(idx+1,j+1+1).Value = r("库存数量")
ws.cells(idx2+1,j+1+1).Value = r("装卸费")
ws.cells(idx2+1,j+1+1).Value = r("仓储费")
ws.cells(idx2+1,idx+1+1).Value = r("拆箱费")
ws.cells(idx2+1,idx+2+1).Value = r("标签费")
ws.cells(idx2+1,idx+3+1).Formula = Cexp(Formula,idx2+1)
idx2 += 1
Next
'wb.Saveas("D:\报表\横向报表.xlsx")
app.visible = True
msgbox("生成完成!!")