VB.Net如何将DataGridView中的每行“n”行导出到Excel中的不同选项卡

我有一个500行和15列的DGV。 我有5名队员。 我必须将相等数量的行分配给我的成员。 所以,在上面的例子中,我必须向DGV的每个团队成员发送100行。 前100行将去Emp#1,行101 – 200将去Emp#2,等等。

我检查了这 一点,但我不能完全能够尝试一些代码来得到这个逻辑工作。

我只在vb.net寻求帮助。

Thx提前。

编辑:我们预算紧张,所以现在不能投资于一个插件。

您可以使用EasyXLS Excel库导出每个5张和100行的Excel文件:

' Create an instance of the class that exports Excel files, having 5 sheets Dim xls As New ExcelDocument(5) Dim n as Integer = dataGridView.Rows.Count()/5 For sheet As Integer = 0 To 4 ' Set sheet names xls.easy_getSheetAt(sheet).setSheetName("Emp#" & (sheet+1)) ' Get the sheet table that stores the data Dim xlsTab As ExcelWorksheet = xls.easy_getSheetAt(sheet) Dim xlsTable = xlsTab.easy_getExcelTable() Dim tableRow = 0 ' Add data in cells For row As Integer = 0 To n - 1 For column As Integer = 0 To dataGridView.Columns.Count() - 1 xlsTable.easy_getCell(tableRow, column).setValue( _ dataGridView.Rows(n*sheet + row).Cells(column).Value.ToString()) Next tableRow = tableRow + 1 Next Next ' Export Excel file xls.easy_WriteXLSXFile("C:\Samples\Excel.xlsx") 

有关格式化以及如何使用此库的更多详细信息,可以从此链接开始,该链接说明如何将DataGridView导出到Excel 。