Private Sub DeleteDuplicateCellValueRow(trgBook As HSSFWorkbook)
'シート取得
Dim trgSheet As HSSFSheet = trgBook.GetSheetAt(0)
'重複リスト作成
Dim jList As New List(Of String)
'合計行数取得
Dim totRow As Integer = trgSheet.LastRowNum
For i As Integer = 1 To totRow
Dim sCellVal As String = GetCellValue(trgSheet, i, 1)
sCellVal = sCellVal.Trim(" ")
If String.IsNullOrEmpty(sCellVal) = False Then
'同じの文字列リストに比較
If jList.Contains(sCellVal) = True Then
'行の削除
trgSheet.ShiftRows(i, trgSheet.LastRowNum, -1)
'行が削除したため合計行数再度設定
totRow = trgSheet.LastRowNum
Else
jList.Add(sCellVal)
End If
End If
Next
End Sub
-----------------------------------
Private Function GetCellValue(ByVal [Sheet] As HSSFSheet, ByVal RowNum As Integer, ByVal ClmNum As Integer) As String
Dim CellValue As String = String.Empty
With Sheet
Try
Dim [cell] As Cell = TryCast(.GetRow(RowNum).GetCell(ClmNum), Cell)
If cell IsNot Nothing Then CellValue = cell.ToString
Catch ex As Exception
End Try
End With
Return CellValue
End Function