miércoles, 7 de octubre de 2020

Crear XLS /abrir XLS

 MyXLSDocumentToCreate is a xlsDocument

// Adds a worksheet
xlsAddWorksheet(MyXLSDocumentToCreate, "Customer list")
MyXLSDocumentToCreate..Worksheet = 1

// Adds a "title" row
MyXLSDocumentToCreate..Cell[1,1] = "Name"
MyXLSDocumentToCreate..Cell[1,1]..AlignmentH = haCenter
MyXLSDocumentToCreate..Cell[1,1]..Font..Bold = True
MyXLSDocumentToCreate..Cell[1,2] = "FirstName"
MyXLSDocumentToCreate..Cell[1,2]..AlignmentH = haCenter
MyXLSDocumentToCreate..Cell[1,2]..Font..Bold = True
MyXLSDocumentToCreate..Cell[1,3] = "Phone"
MyXLSDocumentToCreate..Cell[1,3]..AlignmentH = haCenter
MyXLSDocumentToCreate..Cell[1,3]..Font..Bold = True
MyXLSDocumentToCreate..Cell[1,4] = "Nb orders"
MyXLSDocumentToCreate..Cell[1,4]..AlignmentH = haCenter
MyXLSDocumentToCreate..Cell[1,4]..Font..Bold = True

// Adds data
FOR nCounter = 2 TO 50
    
    // Random data
    MyXLSDocumentToCreate..Cell[2,1] = "Name " + (nCounter-1)
    MyXLSDocumentToCreate..Cell[2,2] = "First name " + (nCounter-1)
    MyXLSDocumentToCreate..Cell[2,3] = "xx.xx.xx.xx.xx"
    MyXLSDocumentToCreate..Cell[2,4] = Random(0,50)
    // Applies a color according to the number of orders
    IF MyXLSDocumentToCreate..Cell[2,4] <= 5 THEN
        // Red
        MyXLSDocumentToCreate..Cell[2,4]..Font..Color = RGB(245, 110, 110)
    ELSE
        // Green
        MyXLSDocumentToCreate..Cell[2,4]..Font..Color = RGB(151, 221, 88)
    END
    
END

// Defines the path of the file to create
sNewFile is string = fTempPath()+["\"]+"XLSTest.xls"
// Saves the XLS document
IF xlsSave(MyXLSDocumentToCreate, sNewFile) = False THEN
    Error("Error while saving the document", ErrorInfo(errMessage))
    RETURN
END

// Closes the document (for its next opening)
xlsClose(MyXLSDocumentToCreate)

// Positions the file path in the edit control
EDT_XLSFile = sNewFile

// Runs the opening code
ExecuteProcess(TAB_Example.BTN_Open, trtClick)

 

 

 

////***** Abrir un documento xls  (2)

// Opens the XLS document
gMyXLSDocument = xlsOpen(EDT_XLSFile, xlsWrite)
IF ErrorOccurred THEN
    Error("Unable to open the document", ErrorInfo())
    RETURN
END

No hay comentarios.:

Publicar un comentario

Try catch end

 // -------------------------------------------------- // Procedure principal que executa uma query com tratamento de exceção // -----------...