Skip to main content
Version: 20 R6 BETA

VP IMPORT DOCUMENT

History
ReleaseChanges
20 R2Support of .sjs documents

VP IMPORT DOCUMENT ( vpAreaName : Text ; filePath : Text { ; paramObj : Object} )

ParameterTypeDescription
vpAreaNameText->4D View Pro area form object name
filePathText->Pathname of the document
paramObjObject->Import options

Description

The VP IMPORT DOCUMENT command imports and displays the document designated by filePath in the 4D View Pro area vpAreaName. The imported document replaces any data already inserted in the area.

In vpAreaName, pass the name of the 4D View Pro area. If you pass a name that does not exist, an error is returned.

In filePath, pass the path and name of the document to be imported. The following formats are supported :

  • 4D View Pro documents (extension ".4vp")
  • Microsoft Excel (extension ".xlsx")
  • text documents (extension ".txt", ".csv", the document must be in utf-8)
  • SpreadJS documents (extension ".sjs")

If the document extension is not a recognized extension, such as .4vp or .xlsx, the document is considered a text document. You must pass a full path, unless the document is located at the same level as the Project folder, in which case you can just pass its name.

An error is returned if the filePath parameter is invalid, or if the file is missing or malformed.

The optional paramObj parameter allows you to define properties for the imported document:

ParameterTypeDescription
formula4D.FunctionA callback method to be launched when the import has completed. You must use a formula returned by the Formula command. See Passing a callback method (formula).
passwordtextMicrosoft Excel only (optional) - The password used to protect a MS Excel document.
csvOptionsobjectoptions for csv import
rangeobjectCell range that contains the first cell where the data will be written. If the specified range is not a cell range, only the first cell of the range is used.
rowDelimitertextRow delimiter. If not present, the delimiter is automatically determined by 4D.
columnDelimitertextColumn delimiter. Default: ","
sjsOptionsobjectoptions for sjs import
calcOnDemandbooleanWhether to calculate formulas only when they are demanded, default is false.
dynamicReferencesbooleanWhether to calculate functions with dynamic references, default is true.
fullRecalcbooleanWhether to calculate after loading the json data, false by default.
includeFormulasbooleanWhether to include the formulas when loading, default is true.
includeStylesbooleanWhether to include the styles when loading, default is true.
includeUnusedStylesbooleanWhether to include the unused name styles when converting excel xml to the json, default is true.
openModeinteger
  • 0 (normal): normal open mode, without lazy and incremental. When opening file, UI and UI event could be refreshed and responsive at specific time points.
  • 1 (lazy): lazy open mode. When opening file, only the active sheet will be loaded directly. Other sheets will be loaded only when they are be used.
  • 2 (incremental): incremental open mode. When opening file, UI and UI event could be refreshed and responsive directly.
  • Notes
    • Importing files in .xslx, .csv, and .sjs formats is asynchronous. With these formats, you must use the formula attribute if you want to start an action at the end of the document processing.
    • When importing a Microsoft Excel-formatted file into a 4D View Pro document, some settings may be lost. You can verify your settings with this list from SpreadJS.
    • For more information on the CSV format and delimiter-separated values in general, see this article on Wikipedia

    Example 1

    You want to import a default 4D View Pro document stored on the disk when the form is open:

    C_TEXT($docPath)
    If(Form event code=On VP Ready) //4D View Pro area loaded and ready
    $docPath:="C:\\Bases\\ViewProDocs\\MyExport.4VP"
    VP IMPORT DOCUMENT("VPArea";$docPath)
    End if

    Example 2

    You want to import a password protected Microsoft Excel document into a 4D View Pro area:

    	//Import code
    var $o : Object
    $o:=New object
    $o.password:="excel123"
    $o.formula:=Formula(myImport)

    VP IMPORT DOCUMENT("ViewProArea";"c:\\tmp\\excelfilefile.xlsx";$o)
    	//myImport callback method
    #DECLARE($area : Text; $filePath : Text; $param : Object; $status : Object)

    If ($status.success)
    ALERT("Import successfully completed")
    Else
    ALERT("Error: "+$status.errorMessage)
    End if

    Example 3

    You want to import a .txt file that uses a comma (",") as delimiter:

    example-import-csv

    $params:=New object
    $params.range:=VP Cells("ViewProArea";0;0;2;5)
    VP IMPORT DOCUMENT("ViewProArea";"c:\\import\\my-file.txt";New object("csvOptions";$params))

    Here's the result: example-import-csv

    See also

    VP EXPORT DOCUMENT
    VP NEW DOCUMENT