我在vb.net中有一个列表,我需要知道如何将此列表导出到excel,它只需显示11列,并且每个产品的行数都会发生变化 我试着但它不起作用。 这是我的代码
Dim objApp As Excel.Application
Dim objBook As Excel.Workbook
Dim objBooks As Excel.Workbooks
Dim objSheets As Excel.Sheets
Dim objSheet As Excel.Worksheet
Dim Rng As Excel.Range
Dim StartRow, StartCol
objApp = New Excel.Application()
objBooks = objApp.Workbooks
objBook = objBooks.Add
objSheets = objBook.Worksheets
objSheet = objSheets(1)
listaReporte = ProcesarKardex()
'this is my list
selectedValues = listaReporte.OrderBy(Function(x)x.fechaOperacion).ToList())
StartRow = 1
StartCol = 1
'write array as a row
With objSheet
Rng = .Range(.Cells(StartRow, StartCol),
.Cells(UBound(selectedValues.ToArray, 1) - LBound(selectedValues.ToArray, 1) + StartRow,
UBound(selectedValues.ToArray, 2) - LBound(selectedValues.ToArray, 2) + StartCol))
End With
Rng.Value = selectedValues ' Row
'Write Array as a Column
StartRow = 3
StartCol = 1
With objSheet
Rng = .Range(.Cells(StartRow, StartCol),
.Cells(UBound(selectedValues.ToArray, 1) - LBound(selectedValues.ToArray, 1) + StartRow,
UBound(selectedValues.ToArray, 2) - LBound(selectedValues.ToArray, 2) + StartCol))
End With
Rng.Value = selectedValues.ToArray ' Column
如果你可以帮助我,那将是很好的,谢谢你提前!!