createXLSX
To dynamically create customizable, styled, multi-sheet Excel files directly from databases
With this function, you can create an XLSX file with customizable content and multiple sheets, reflecting the data and style defined in the input parameters.
The resulting file is saved directly in Ninox, offering dynamic data management and formatting options.
Syntax
createXLSX(nid, any, string)
Return
file
Examples
sample_script (2KB)
sample_result.xlsx (7KB)
Using createXLSX
To create an Excel file with the createXLSX
function:
- Create a Button field: When clicked, the button triggers a function to create an Excel file from the data provided in the formula editor.
- Create an Image field: Serves a link, allowing you to download the file directly.
Now enable edit mode and click the On click field. In the formula editor:
- Define the columns and rows.
- Define the worksheet structure.
- Use the
createXLSX
function. - Define styles and formatting (optional).
- Save the script. Create the Excel file by clicking the button.
Define columns and rows
First, create an object to define the columns:
let columns = [
{
header: "Name",
key: "name",
width: 10,
},
{
header: "Age",
key: "age",
width: 10
},
{
header: "URL",
key: "url",
width: 30
},
{
header: "Description",
key: "description",
width: 20
}
];
Next, define the rows. You can use Supported special fields (read below), if you need to:
let rows = [
{
name: "Luis Gómez",
age: 30,
url: {
text: "www.google.com",
hyperlink: "http://www.google.com",
tooltip: "www.google.com"
}
},
{
name: "Maria Silva",
age: 25,
url: {
text: "www.google.com",
hyperlink: "http://www.google.com",
tooltip: "www.google.com"
}
},
{
name: "Ayesha Khan",
age: 35,
url: {
text: "www.google.com",
hyperlink: "http://www.google.com",
tooltip: "www.google.com"
}
},
{
name: "Li Wei",
age: 40,
url: {
text: "www.google.com",
hyperlink: "http://www.google.com",
tooltip: "www.google.com"
}
},
{
name: "Rajesh Kumar",
age: 21,
url: {
text: "www.google.com",
hyperlink: "http://www.google.com",
tooltip: "www.google.com"
}
},
{
name: "Sofia Müller",
age: 24,
url: {
text: "www.google.com",
hyperlink: "http://www.google.com",
tooltip: "www.google.com"
}
}
];
Define worksheet structure
Define a worksheet with columns and rows:
let worksheets = {
Sheet1: {
columns: columns,
rows: rows
}
};
Use createXLSX
Call the createXLSX
function with the defined worksheets:
Image := createXLSX(this, worksheets, "example.xlsx")
Define styles and formatting (optional)
Apply style to a header cell:
let columns = [
{
header: "Name",
key: "name",
width: 10,
headerStyle: {
font: {
bold: true
}
}
}
];
Apply style to an entire column except the header:
let columns = [
{
header: "Name",
key: "name",
width: 10,
style: {
font: {
name: "Comic Sans MS"
}
}
}
];
Apply style to an entire row:
let rows = [
{
name: "Luis Gómez",
age: 30,
// hyperlink field
url: {
text: "www.google.com",
hyperlink: "http://www.google.com",
tooltip: "www.google.com"
},
styles: [
{
fill: {
type: "pattern",
pattern: "solid",
fgColor: {
argb: "F08080"
}
}
}
]
}
];
Apply style to specific cells in a row:
let rows = [
{
name: "Luis Gómez",
age: 30,
// hyperlink field
url: {
text: "www.google.com",
hyperlink: "http://www.google.com",
tooltip: "www.google.com"
},
styles: [
{
targets: ["name", "age"],
fill: {
type: "pattern",
pattern: "solid",
fgColor: {
argb: "F08080"
}
}
}
]
}
];
Create Excel file
Finally, when you've saved your script, click the button to create an Excel file.
Supported styles and formatting options
Font
{
font: {
name: "Arial Black",
color: { argb: "FF00FF00" },
family: 2,
size: 14,
italic: true,
underline: true,
bold: true
}
}
Font formatting options
Font property | Description | Example value(s) |
---|---|---|
name | Specifies the font name. | "Arial" "Calibri" etc. |
family | Specifies the font family for fallback as an integer value. | 1 - Serif 2 - Sans Serif 3 - Mon Others - unknown |
scheme | Specifies the font scheme. | "minor" "major" "none" |
charset | Specifies the font character set as an integer value. | 1 2 etc. |
size | Specifies the font size as an integer value. | 9 10 12 16 etc. |
color | Specifies the font color as an ARGB object. | { argb: "FFFF0000" } |
bold | Specifies whether the font is bold, indicating weight. | true false |
italic | Specifies whether the font is italic, indicating slope. | true false |
underline | Specifies the font underline style. | true false "none" "single" "double" "singleAccounting" "doubleAccounting" |
strike | Specifies whether the font has strikethrough. | true false |
outline | Specifies whether the font has an outline. | true false |
vertAlign | Specifies the font's vertical alignment. | "superscript" "subscript" |
Alignment
{ alignment: { vertical: "top", horizontal: "left" }
Excel-Datei erstellen
Wenn Sie Ihr Skript gespeichert haben, klicken Sie abschließend auf den Button, um eine Excel-Datei zu erstellen.
Unterstützte Stil- und Formatierungsoptionen
Schriftart
{
font: {
name: "Arial Black",
color: { argb: "FF00FF00" },
family: 2,
size: 14,
italic: true,
underline: true,
bold: true
}
}
Schriftformatierungsoptionen
Schrifteigenschaft | Beschreibung | Beispielwert(e) |
---|---|---|
name | Gibt den Schriftnamen an. | "Arial" "Calibri" usw. |
family | Gibt die Schriftfamilie für den Fallback als Ganzzahlwert an. | 1 - Serif 2 - Sans Serif 3 - Monospace Andere - unbekannt |
scheme | Gibt das Schriftschema an. | "minor" "major" "none" |
charset | Gibt den Schriftzeichensatz als Ganzzahlwert an. | 1 2 usw. |
size | Gibt die Schriftgröße als Ganzzahlwert an. | 9 10 12 16 usw. |
color | Gibt die Schriftfarbe als ARGB-Objekt an. | { argb: "FFFF0000" } |
bold | Gibt an, ob die Schrift fett ist und zeigt das Gewicht an. | true false |
italic | Gibt an, ob die Schrift kursiv ist und zeigt die Neigung an. | true false |
underline | Gibt den Unterstreichungsstil der Schrift an. | true false "none" "single" "double" "singleAccounting" "doubleAccounting" |
strike | Gibt an, ob die Schrift durchgestrichen ist. | true false |
outline | Gibt an, ob die Schrift eine Kontur hat. | true false |
vertAlign | Gibt die vertikale Ausrichtung der Schrift an. | "superscript" "subscript" |
Ausrichtung
{ alignment: { vertical: "top", horizontal: "left" }
Alignment options
Alignment property | Description | Example value(s) |
---|---|---|
horizontal | Specifies the horizontal alignment. | "left" "center" "right" "fill" "justify" "centerContinuous" "distributed" |
vertical | Specifies the vertical alignment. | "top" "middle" "bottom" "distributed" "justify" |
wrapText | Specifies whether the text should wrap. | true false |
shrinkToFit | Specifies whether to shrink the text to fit in the cell. | true false |
indent | Specifies the indent level. | 0 1 2 etc. |
readingOrder | Specifies the reading order. | "rtl" "ltr" |
textRotation | Specifies the text rotation. | 0 45 90 -45 etc. |
Fill
{
fill: {
type: "pattern",
pattern: "solid",
fgColor: { argb: "FF0000FF" }
}
}
Fill options
Fill property | Description | Example value(s) |
---|---|---|
type | Specifies the fill type. | "pattern" "gradient" |
pattern | Specifies the fill pattern (when type is "pattern"). | "solid" "darkGray" "mediumGray" "lightGray" "gray125" "gray0625" "darkHorizontal" "darkVertical" "darkDown" "darkUp" "darkGrid" "darkTrellis" "lightHorizontal" "lightVertical" "lightDown" "lightUp" "lightGrid" "lightTrellis" |
fgColor | Specifies the foreground color as an ARGB object. | { argb: "FFFF0000" } |
bgColor | Specifies the background color as an ARGB object. | { argb: "FF0000FF" } |
gradient | Specifies the gradient (when type is "gradient"). | { degree: 90, stops: [{ position: 0, color: { argb: "FF0000FF" } }, { position: 1, color: { argb: "FFFF0000" } }] } |
Border
{
border: {
top: { style: "thin", color: { argb: "FF000000" } },
left: { style: "thin", color: { argb: "FF000000" } },
bottom: { style: "thin", color: { argb: "FF000000" } },
right: { style: "thin", color: { argb: "FF000000" } }
}
}
Border options
Border property | Description | Example value(s) |
---|---|---|
top, left, bottom, right | Specifies the border for each side of the cell. | { style: "thin", color: { argb: "FF000000" } } |
diagonal | Specifies the diagonal border of the cell. | { style: "thin", color: { argb: "FF000000" } } |
diagonalDown | Specifies whether to draw the diagonal border from top-left to bottom-right. | true false |
diagonalUp | Specifies whether to draw the diagonal border from bottom-left to top-right. | true false |
Border style options
Border style | Description |
---|---|
thin | Thin border |
dotted | Dotted border |
dashDot | Dash-dot border |
hair | Hair border |
dashDotDot | Dash-dot-dot border |
slantDashDot | Slanted dash-dot border |
mediumDashed | Medium dashed border |
mediumDashDotDot | Medium dash-dot-dot border |
mediumDashDot | Medium dash-dot border |
medium | Medium border |
double | Double border |
thick | Thick border |
Antwort
Content aside
- vor 18 StundenZuletzt aktiv
- 9Ansichten
-
1
Folge bereits