Android Question save the Excel file and open it on PC, the file size is 0 ???

dongsool

Member
Licensed User
I checked the file size before creating and saving the Excel file.

File size is not always 0 before saving to UMS

However, errors often occur when I open a file on PC.

In that case, the file size will also be marked as zero.

What verification procedure is required after file creation until completion?

B4X:
Sub SaveTable
    
    pathUSB = Utils.getpathUSB
    Dim fileName As String
    
    If pathUSB <> "" Then
        ProgressDialogShow2("Please wait",False)
        LogColor(pathUSB,Colors.Yellow)
        
        fileName = MachineConfig.machineName & "-" & Utils.GetTime(DateTime.Now) & ".xls"
        Dim newWorkbook As WritableWorkbook
        newWorkbook.Initialize(pathUSB, fileName)
        Dim sheet1 As WritableSheet
        sheet1 = newWorkbook.AddSheet("tray", 0)
    
        #region CELL Format
        Dim cellFormat As WritableCellFormat
        cellFormat.Initialize2(cellFormat.FONT_ARIAL, 12, True, False, False, cellFormat.COLOR_GREEN)
        cellFormat.HorizontalAlignment = cellFormat.HALIGN_CENTRE
        cellFormat.SetBorder(cellFormat.BORDER_ALL, cellFormat.BORDER_STYLE_MEDIUM, cellFormat.COLOR_BLACK)
        cellFormat.SetBorder(cellFormat.BORDER_BOTTOM, cellFormat.BORDER_STYLE_THICK, cellFormat.COLOR_BLUE)
        cellFormat.VertivalAlignment = cellFormat.VALIGN_CENTRE
        cellFormat.BackgroundColor = cellFormat.COLOR_GREY_25_PERCENT
        #end region
    
        Dim col As Int = 0
        For Each lbl As Label In table1.Header
            Dim cell As WritableCell
            cell.InitializeText(col, 0, lbl.Text)
            cell.SetCellFormat(cellFormat)
            sheet1.AddCell(cell)
            sheet1.SetColumnWidth(col, 15)
            col = col + 1
        Next
        sheet1.SetColumnWidth(2, 40)
        sheet1.SetRowHeight(0, 15)
    
        Dim rowsFormat As WritableCellFormat
        rowsFormat.Initialize
        rowsFormat.HorizontalAlignment = rowsFormat.HALIGN_CENTRE
        For col = 0 To table1.NumberOfColumns - 1
            For row = 0 To table1.Size - 1
                Dim cell As WritableCell
                cell.InitializeText(col, row + 1, table1.GetValue(col, row))
                cell.SetCellFormat(rowsFormat)
                sheet1.AddCell(cell)
            Next
        Next
        
        newWorkbook.Write
        newWorkbook.Close
                
        LogColor("File Size: " & File.Size(pathUSB,fileName),Colors.Green)
        
        ProgressDialogHide
        ToastMessageShow("File Saved",False)
                
    Else
        ToastMessageShow("UMS not found",False)
    End If
        
End Sub
 
Last edited:
Top