Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

Matrix.CSV

Queries text of matrix for CSV export.

Component Version macOS Windows Linux Server iOS SDK
Matrix 9.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "Matrix.CSV"; MatrixRef { ; FirstRow; LastRow; firstCol; lastCol; rowSeparator; colSeparator; Flags } )   More

Parameters

Parameter Description Example Flags
MatrixRef The matrix reference number. $matrix
FirstRow The index of first row.
Default is 0.
0 Optional
LastRow The index of last row.
Default is Matrix.Height-1.
5 Optional
firstCol The index of first column.
Default is 0.
0 Optional
lastCol The index of last column.
Default is Matrix.Width-1.
6 Optional
rowSeparator The row separator.
Default is CR.
Can be more than one character.
Char(13) Optional
colSeparator The column separator.
Default is semicolon.
Can be more than one character.
";" Optional
Flags Various flags.
1: Pass 1 to put all text values in quotes.
2: Include column names in first row (new in v13.1).
0 Optional

Added in version 13.0.

Result

Returns text or error.

Description

Queries text of matrix for CSV export.
You can use this method to quickly get all values in a given area as text.
If needed, the plugin puts values in quotes and escape quotes and newlines.

Please use Text.WriteTextFile to write to text file if you need CSV export.

Examples

Show matrix in dialog as CSV:

Show Custom Dialog [ “The Matrix" ; MBS( "Matrix.CSV"; $matrix; 0; 2; 0; 2; Char(13); " " ) ]

Export to CSV with adjusting the numbers:

# Destination file
Set Variable [ $path ; Value: MBS( "Path.AddPathComponent"; MBS( "Folders.UserDesktop" ); "export.csv" ) ]
#
# query data via SQL
Set Variable [ $Felder ; Value: "B01_Marke¶B02_Artikelnummer¶B03_Bezeichnung¶B04_Produktgruppe_Code¶B05_Produktgruppe_Text¶B06_Status_Code¶B07_Status_Text¶B08_Ersatznummer¶B09_Verpackungseinheit¶B12_VK_Inkl¶B13_VK_Exkl¶B14_RG¶B15_Haendlerpreis_STD_Exkl¶B16_Haendlerpreis_URG_Exkl¶B23_Er…" ]
Set Variable [ $matrix ; Value: MBS( "Matrix.NewWithSQL"; ""; "SELECT \"" & Substitute($felder; ¶; "\", \"") & "\" FROM CSVTest") ]
#
# now chnage the formatting of the numbers to 4 digits and using dot
Set Variable [ $rowCount ; Value: MBS( "Matrix.Height"; $matrix ) ]
Set Variable [ $row ; Value: 0 ]
If [ $row < $rowCount ]
    Loop [ Flush: Always ]
        # convert numbers
        #
        Set Variable [ $column ; Value: 8 // B09_Verpackungseinheit ]
        Set Variable [ $value ; Value: MBS( "Matrix.GetValue"; $matrix; $Row; $Column ) ]
        Set Variable [ $value ; Value: MBS("Math.FormatNumber"; $value; 4; "."; "") ]
        Set Variable [ $r ; Value: MBS( "Matrix.SetValue"; $matrix; $Row; $Column; $value ) ]
        #
        Set Variable [ $column ; Value: 9 // B12_VK_Inkl ]
        Set Variable [ $value ; Value: MBS( "Matrix.GetValue"; $matrix; $Row; $Column ) ]
        Set Variable [ $value ; Value: MBS("Math.FormatNumber"; $value; 4; "."; "") ]
        Set Variable [ $r ; Value: MBS( "Matrix.SetValue"; $matrix; $Row; $Column; $value ) ]
        #
        Set Variable [ $column ; Value: 10 // B13_VK_Exkl ]
        Set Variable [ $value ; Value: MBS( "Matrix.GetValue"; $matrix; $Row; $Column ) ]
        Set Variable [ $value ; Value: MBS("Math.FormatNumber"; $value; 4; "."; "") ]
        Set Variable [ $r ; Value: MBS( "Matrix.SetValue"; $matrix; $Row; $Column; $value ) ]
        #
        Set Variable [ $column ; Value: 11 // B14_RG ]
        Set Variable [ $value ; Value: MBS( "Matrix.GetValue"; $matrix; $Row; $Column ) ]
        Set Variable [ $value ; Value: MBS("Math.FormatNumber"; $value; 4; "."; "") ]
        Set Variable [ $r ; Value: MBS( "Matrix.SetValue"; $matrix; $Row; $Column; $value ) ]
        #
        Set Variable [ $column ; Value: 12 // B15_Haendlerpreis_STD_Exkl ]
        Set Variable [ $value ; Value: MBS( "Matrix.GetValue"; $matrix; $Row; $Column ) ]
        Set Variable [ $value ; Value: MBS("Math.FormatNumber"; $value; 4; "."; "") ]
        Set Variable [ $r ; Value: MBS( "Matrix.SetValue"; $matrix; $Row; $Column; $value ) ]
        #
        Set Variable [ $column ; Value: 13 // B16_Haendlerpreis_URG_Exkl ]
        Set Variable [ $value ; Value: MBS( "Matrix.GetValue"; $matrix; $Row; $Column ) ]
        Set Variable [ $value ; Value: MBS("Math.FormatNumber"; $value; 4; "."; "") ]
        Set Variable [ $r ; Value: MBS( "Matrix.SetValue"; $matrix; $Row; $Column; $value ) ]
        #
        # next
        Set Variable [ $row ; Value: $row + 1 ]
        Exit Loop If [ $row$rowCount ]
    End Loop
End If
#
# CSV
Set Variable [ $r ; Value: MBS("Matrix.SetColumnNames"; $matrix; $Felder) ]
Set Variable [ $csv ; Value: MBS( "Matrix.CSV"; $matrix; 0; ""; 0; ""; Char(13); ";"; 2) ]
#
# Line endings for Windows
Set Variable [ $csv ; Value: MBS("Text.ReplaceNewLine"; $csv; 3) ]
#
# Write CSV file
Set Variable [ $r ; Value: MBS("Text.WriteTextFile"; $csv; $path; "UTF-8") ]
#
# and cleanup
Set Variable [ $r ; Value: MBS("Matrix.Release"; $matrix) ]

We escape returns:

Let ( [
  m = MBS("Matrix.New"; 1; 1);
  r = MBS("Matrix.SetValue"; m; 0; 0; "Hello" & Char ( 10 ) & "World¶Test");
  csv = MBS("Matrix.CSV"; m);
  r = MBS("Matrix.Release"; m)
]; csv )

Example result: "Hello\nWorld\rTest"

See also

Release notes

Example Databases

Blog Entries

This function checks for a license.

Created 8th April 2019, last changed 6th February 2026


Matrix.Avg - Matrix.CSVSplit