Fix common module and simplify Z1 export

This commit is contained in:
updsv7
2026-04-13 18:21:42 +09:00
parent 9338e4adbf
commit c9844a6cfe
2 changed files with 36 additions and 25 deletions

View File

@@ -159,7 +159,8 @@ End Sub
' dataColumns - array of column numbers to export
' Returns: CSV content string
' ============================================================
Function BuildCSVContent(ByVal ws As Worksheet, ByVal startRow As Long, ByVal endRow As Long, ByRef dataColumns() As Long, Optional ByVal headerRow As Long = 0) As String
Function BuildCSVContent(ByVal ws As Worksheet, ByVal startRow As Long, ByVal endRow As Long, ByVal startCol As Long, ByVal endCol As Long, Optional ByVal headerRow As Long = 0, Optional ByVal colStep As Long = 1) As String
' Simpler version: export continuous columns
Dim csvContent As String
Dim r As Long
Dim col As Long
@@ -167,11 +168,13 @@ Function BuildCSVContent(ByVal ws As Worksheet, ByVal startRow As Long, ByVal en
' Build header if specified
If headerRow > 0 Then
For col = LBound(dataColumns) To UBound(dataColumns)
If col = LBound(dataColumns) Then
csvContent = Trim(ws.Cells(headerRow, dataColumns(col)).Value)
firstCol = True
For col = startCol To endCol Step colStep
If firstCol Then
csvContent = Trim(ws.Cells(headerRow, col).Value)
firstCol = False
Else
csvContent = csvContent & "," & Trim(ws.Cells(headerRow, dataColumns(col)).Value)
csvContent = csvContent & "," & Trim(ws.Cells(headerRow, col).Value)
End If
Next col
csvContent = csvContent & vbLf
@@ -179,14 +182,14 @@ Function BuildCSVContent(ByVal ws As Worksheet, ByVal startRow As Long, ByVal en
' Build data rows
For r = startRow To endRow
If Len(Trim(ws.Cells(r, dataColumns(LBound(dataColumns))).Value & "")) > 0 Then
If Len(Trim(ws.Cells(r, startCol).Value & "")) > 0 Then
firstCol = True
For col = LBound(dataColumns) To UBound(dataColumns)
For col = startCol To endCol Step colStep
If firstCol Then
csvContent = csvContent & CleanCSVField(ws.Cells(r, dataColumns(col)).Value)
csvContent = csvContent & CleanCSVField(ws.Cells(r, col).Value)
firstCol = False
Else
csvContent = csvContent & "," & CleanCSVField(ws.Cells(r, dataColumns(col)).Value)
csvContent = csvContent & "," & CleanCSVField(ws.Cells(r, col).Value)
End If
Next col
csvContent = csvContent & vbLf