具有文档格式的VB过滤器.OpenXML,封闭XML

时间:2018-07-26 10:44:46

标签: excel vb.net

我正在尝试编写代码,并尝试为excel行和列创建过滤器。标头是字符串。

示例:

+----------+------------------+----------------+
| User Id  |     PartNuer     |   Numbers ETC  |
+----------+------------------+----------------+
|    3     | `gdfgfdg34fddwf` |                |
|   23     |     rerwerw      |                |
|    5     |                  |                |
|    6     |                  |                |
+----------+------------------+----------------+

如何查看用户ID是否为Integer,其他用户为string

Imports System
Imports System.IO
Imports System.Data
Imports System.Collections.Generic
Imports ClosedXML.Excel
Imports DocumentFormat.OpenXml.Spreadsheet

Partial Class VB Inherits System.Web.UI.Page
    Protected Sub ImportExcel(sender As Object, e As EventArgs)
        'Open the Excel file using ClosedXML.
        Using workBook As New XLWorkbook(FileUpload1.PostedFile.InputStream)
            'Read the first Sheet from Excel file.
            Dim workSheet As IXLWorksheet = workBook.Worksheet(1)

            'Create a new DataTable.
            Dim dt As New DataTable()

            Try
                'Loop through the Worksheet rows.
                Dim firstRow As Boolean = True
                For Each row As IXLRow In workSheet.Rows()
                    'Use the first row to add columns to DataTable.
                    If firstRow Then
                        For Each cell As IXLCell In row.Cells()
                            dt.Columns.Add(cell.Value.ToString())
                        Next
                        firstRow = False
                    Else
                        'Add rows to DataTable.
                        dt.Rows.Add()
                        Dim i As Integer = 0
                        For Each cell As IXLCell In row.Cells()
                            dt.Rows(dt.Rows.Count - 1)(i) = cell.Value.ToString()
                            i += 1
                        Next
                    End If

                    GridView1.DataSource = dt
                    GridView1.DataBind()
                Next

            Catch
                MsgBox("tabela Description nu este introdusa bine")
                MsgBox("Unele Cell-uri din Excel nu sunt introduse bine ")
            End Try
        End Using
    End Sub
End Class

我不知道该怎么办。

0 个答案:

没有答案