Excel Column-Width

Discussão em 'StackOverflow' iniciado por fdantas, Agosto 10, 2016.

  1. fdantas

    fdantas Administrator Moderador

    I would like to ask on how to export to excel with a fixed column-width. Since the width of a column would depend on the character length.

    Here is my sample code: for both Excel and Macro

    Excel Procedure:

    DEFINE VARIABLE h-excel AS COM-HANDLE NO-UNDO.
    DEFINE VARIABLE h-sheet AS COM-HANDLE.
    DEFINE VAR w-invname AS CHAR INITIAL "file-path\excel.xls".

    CREATE "Excel.Application" h-excel.

    h-sheet = h-excel:Workbooks:OPEN (w-invname,,FALSE,,,,,,,,,,FALSE) NO-ERROR.
    h-excel:visible = true.

    h-excel:Cells:Select.

    h-excel:Run("loading").

    /*h-excel:Range("A" + STRING(5)):VALUE = "Date Covered " + STRING(fifr) + " - " + STRING(fito).*/

    h-excel:Range("A6"):Select.

    RELEASE OBJECT h-sheet.
    RELEASE OBJECT h-excel.

    END PROCEDURE.


    Excel Macro:

    Sub loading()
    '
    ' loading Macro

    '
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;file-path\text.txt", _
    Destination:=Range("A6"))
    .Name = "CarSumm"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .TextFilePromptOnRefresh = False
    .TextFilePlatform = xlWindows
    .TextFileStartRow = 1
    .TextFileParseType = xlDelimited
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileConsecutiveDelimiter = False
    .TextFileTabDelimiter = False
    .TextFileSemicolonDelimiter = False
    .TextFileCommaDelimiter = False
    .TextFileSpaceDelimiter = False
    .TextFileOtherDelimiter = "|"
    .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
    .Refresh BackgroundQuery:=False
    End With
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 6
    ActiveWindow.ScrollColumn = 9
    End Sub

    Continue reading...

Compartilhe esta Página