1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
Public Class StockedItems
Public Sub ReadExcelFileSAX(ByVal fileName As String)
Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Open(fileName, False)
Dim workbookPart As WorkbookPart = spreadsheetDocument.WorkbookPart
Dim stringTable = workbookPart.GetPartsOfType(Of SharedStringTablePart).FirstOrDefault()
Dim worksheetPart As WorksheetPart
Dim cell As Cell
Dim value As String
Dim reader As OpenXmlReader
'Dim objWriter As System.IO.StreamWriter
For Each s As Sheet In workbookPart.Workbook.Sheets
If s.Name = "Products" Then
worksheetPart = workbookPart.GetPartById(s.Id)
reader = OpenXmlReader.Create(worksheetPart)
While reader.Read()
If reader.ElementType = GetType(Cell) Then
cell = reader.LoadCurrentElement()
If cell.DataType IsNot Nothing Then
Select Case (cell.DataType.Value)
Case CellValues.SharedString
If stringTable IsNot Nothing Then
value = stringTable.SharedStringTable.ElementAt(Integer.Parse(cell.InnerText)).InnerText
End If
Case CellValues.Boolean
Select Case cell.InnerText
Case "0"
value = "FALSE"
Case Else
value = "TRUE"
End Select
End Select
Else
value = cell.InnerText
End If
End If
End While
MsgBox("Products complete")
ElseIf s.Name = "Contract Pricing" Then
worksheetPart = workbookPart.GetPartById(s.Id)
reader = OpenXmlReader.Create(worksheetPart)
While reader.Read()
If reader.ElementType = GetType(CellValue) Then
value = reader.GetText()
End If
End While
MsgBox("Price complete")
End If
Next
End Using
End Sub
End Class |
Partager