DOCUMENTS 5 - PortalScripting API
Public Member Functions | Public Attributes | List of all members
XLSXWriter Class Reference

The XLSXWriter class allows creating files in the Excel 2007+ XLSX file format by use of the library Libxlsxwriter. More...

Public Member Functions

boolean activateChartsheet (var chartsheet)
 Make a chartsheet the active, i.e., visible chartsheet. More...
 
boolean activateWorksheet (var worksheet)
 Make a worksheet the active, i.e., visible worksheet. More...
 
XLSXChart addChart (number type)
 Create a new chart to be added to a worksheet/chartsheet. More...
 
XLSXChartsheet addChartsheet (String name="")
 Add a new chartsheet to the current Excel document. More...
 
XLSXWorksheet addFormat (String name)
 Create a new format object to format cells in worksheets. More...
 
XLSXWorksheet addWorksheet (String name="")
 Add a new worksheet to the current Excel document. More...
 
XLSXChartsheet getChartsheetByName (String name)
 Get a chartsheet object from its name. More...
 
String getFilePath ()
 Get the file path of the created Excel file. More...
 
String getLastError ()
 Function to get the description of the last error that occurred. More...
 
XLSXWorksheet getWorksheetByName (String name)
 Get a worksheet object from its name. More...
 
boolean hideChartsheet (var chartsheet)
 Hide the given chartsheet. More...
 
boolean hideWorksheet (var worksheet)
 Hide the given worksheet. More...
 
boolean save ()
 Write the Excel file to disk and free any memory allocated internally to the Excel file. More...
 
boolean selectChartsheet (var chartsheet)
 Set a chartsheet tab as selected. More...
 
boolean selectWorksheet (var worksheet)
 Set a worksheet tab as selected. More...
 
boolean setProperties (String title, String subject, String author, String manager, String company, String category, String keywords, String comments, String status, String hyperlinkBase)
 Set the document properties. More...
 
XLSXWriter XLSXWriter (String filename)
 Create a new XLSXWriter object with a given filename. More...
 

Public Attributes

String version
 String value containing the version number of the used library Libxlsxwriter. More...
 
Predefined values for common colors

The colors are specified using a HTML style RGB integer value. For convenience a limited number of common colors are predefined as follows.

Note
Black in HTML is actually 0x000000 but XLSXWriter.COLOR_BLACK is defined as 0x1000000 to avoid confusion with an undefined or Zero color value. It is converted to the correct HTML code internally.
See also
XLSXWorksheet.setTabColor(number color), XLSXChartsheet.setTabColor(number color)
XLSXFormat.setFontColor(number color), XLSXFormat.setBorderColor(String border, number color)
XLSXFormat.setForegroundColor(number color), XLSXFormat.setBackgroundColor(number color)
Since
DOCUMENTS 5.0e
number COLOR_BLACK
 Black defined as 0x1000000.
 
number COLOR_BLUE
 Blue defined as 0x0000FF.
 
number COLOR_BROWN
 Brown defined as 0x800000.
 
number COLOR_CYAN
 Cyan defined as 0x00FFFF.
 
number COLOR_GRAY
 Gray defined as 0x808080.
 
number COLOR_GREEN
 Green defined as 0x008000.
 
number COLOR_LIME
 Lime defined as 0x00FF00.
 
number COLOR_MAGENTA
 Magenta defined as 0xFF00FF.
 
number COLOR_NAVY
 Navy defined as 0x000080.
 
number COLOR_ORANGE
 Orange defined as 0xFF6600.
 
number COLOR_PINK
 Pink defined as 0xFF00FF.
 
number COLOR_PURPLE
 Purple defined as 0x800080.
 
number COLOR_RED
 Red defined as 0xFF0000.
 
number COLOR_SILVER
 Silver defined as 0xC0C0C0.
 
number COLOR_WHITE
 White defined as 0xFFFFFF.
 
number COLOR_YELLOW
 Yellow defined as 0xFFFF00.
 
Cell border styles

The constants build an enumeration of the available values for cell border styles.

See also
XLSXFormat.setBorderStyle(String border, number style)
Since
DOCUMENTS 5.0e
number BORDER_NONE
 No border.
 
number BORDER_THIN
 Thin border style.
 
number BORDER_MEDIUM
 Medium border style.
 
number BORDER_DASHED
 Dashed border style.
 
number BORDER_DOTTED
 Dotted border style.
 
number BORDER_THICK
 Thick border style.
 
number BORDER_DOUBLE
 Double border style.
 
number BORDER_HAIR
 Hair border style.
 
number BORDER_MEDIUM_DASHED
 Medium dashed border style.
 
number BORDER_DASH_DOT
 Dash-dot border style.
 
number BORDER_MEDIUM_DASH_DOT
 Medium dash-dot border style.
 
number BORDER_DASH_DOT_DOT
 Dash-dot-dot border style.
 
number BORDER_MEDIUM_DASH_DOT_DOT
 Medium dash-dot-dot border style.
 
number BORDER_SLANT_DASH_DOT
 Slant dash-dot border style.
 
Text alignments

These constants build an enumeration of the available values for the horizontal and vertical text alignment within a cell.

See also
XLSXFormat.setAlign(number alignment)
Since
DOCUMENTS 5.0e
number ALIGN_NONE
 No alignment. Cell will use Excel's default for the data type.
 
number ALIGN_LEFT
 Left horizontal alignment.
 
number ALIGN_CENTER
 Center horizontal alignment.
 
number ALIGN_RIGHT
 Right horizontal alignment.
 
number ALIGN_FILL
 Cell fill horizontal alignment.
 
number ALIGN_JUSTIFY
 Justify horizontal alignment.
 
number ALIGN_CENTER_ACROSS
 Center Across horizontal alignment.
 
number ALIGN_DISTRIBUTED
 Distributed horizontal alignment.
 
number ALIGN_VERTICAL_TOP
 Top vertical alignment.
 
number ALIGN_VERTICAL_BOTTOM
 Bottom vertical alignment.
 
number ALIGN_VERTICAL_CENTER
 Center vertical alignment.
 
number ALIGN_VERTICAL_JUSTIFY
 Justify vertical alignment.
 
number ALIGN_VERTICAL_DISTRIBUTED
 Distributed vertical alignment.
 
Background Patterns

These constants build an enumeration of the available fill patterns for the background of a cell.

See also
XLSXFormat.setBackgroundPattern(number pattern)
Since
DOCUMENTS 5.0e
number PATTERN_NONE
 Empty pattern.
 
number PATTERN_SOLID
 Solid pattern.
 
number PATTERN_MEDIUM_GRAY
 Medium gray pattern.
 
number PATTERN_DARK_GRAY
 Dark gray pattern.
 
number PATTERN_LIGHT_GRAY
 Light gray pattern.
 
number PATTERN_DARK_HORIZONTAL
 Dark horizontal line pattern.
 
number PATTERN_DARK_VERTICAL
 Dark vertical line pattern.
 
number PATTERN_DARK_DOWN
 Dark diagonal stripe pattern.
 
number PATTERN_DARK_UP
 Reverse dark diagonal stripe pattern.
 
number PATTERN_DARK_GRID
 Dark grid pattern.
 
number PATTERN_DARK_TRELLIS
 Dark trellis pattern.
 
number PATTERN_LIGHT_HORIZONTAL
 Light horizontal Line pattern.
 
number PATTERN_LIGHT_VERTICAL
 Light vertical line pattern.
 
number PATTERN_LIGHT_DOWN
 Light diagonal stripe pattern.
 
number PATTERN_LIGHT_UP
 Reverse light diagonal stripe pattern.
 
number PATTERN_LIGHT_GRID
 Light grid pattern.
 
number PATTERN_LIGHT_TRELLIS
 Light trellis pattern.
 
number PATTERN_GRAY_125
 12.5% gray pattern
 
number PATTERN_GRAY_0625
 6.25% gray pattern
 
Chart types

These constants build an enumeration of the available chart types.

See also
XLSXWriter.addChart(number type)
Since
DOCUMENTS 5.0e
number CHART_AREA
 Area chart.
 
number CHART_AREA_STACKED
 Area chart - stacked.
 
number CHART_AREA_STACKED_PERCENT
 Area chart - percentage stacked.
 
number CHART_BAR
 Bar chart.
 
number CHART_BAR_STACKED
 Bar chart - stacked.
 
number CHART_BAR_STACKED_PERCENT
 Bar chart - percentage stacked.
 
number CHART_COLUMN
 Column chart.
 
number CHART_COLUMN_STACKED
 Column chart - stacked.
 
number CHART_COLUMN_STACKED_PERCENT
 Column chart - percentage stacked.
 
number CHART_DOUGHNUT
 Doughnut chart.
 
number CHART_LINE
 Line chart.
 
number CHART_PIE
 Pie chart.
 
number CHART_SCATTER
 Scatter chart.
 
number CHART_SCATTER_STRAIGHT
 Scatter chart - straight.
 
number CHART_SCATTER_STRAIGHT_WITH_MARKERS
 Scatter chart - straight with markers.
 
number CHART_SCATTER_SMOOTH
 Scatter chart - smooth.
 
number CHART_SCATTER_SMOOTH_WITH_MARKERS
 Scatter chart - smooth with markers.
 
number CHART_RADAR
 Radar chart.
 
number CHART_RADAR_WITH_MARKERS
 Radar chart - with markers.
 
number CHART_RADAR_FILLED
 Radar chart - filled.
 

Detailed Description

The XLSXWriter class allows creating files in the Excel 2007+ XLSX file format by use of the library Libxlsxwriter.

An XLSXWriter object represents an entire Excel document. It can be used to write text, numbers, formulas and hyperlinks to multiple worksheets. It supports features such as:

Note
However, the XLSXWriter can only create new files. It CANNOT READ OR MODIFY existing files.
Since
DOCUMENTS 5.0e
Example:
var writer = new XLSXWriter("c:\\tmp\\writer.xlsx");
// Add a worksheet with a user defined sheet name.
var worksheet1 = writer.addWorksheet("Worksheet1");
// Add a cell format.
var format1 = writer.addFormat("format1");
// Set the bold property for the format.
format1.setFontStyle("bold");
// Set the alignment for the format
format1.setAlign(writer.ALIGN_CENTER);
// Write formatted data.
worksheet1.writeCell("string", 0, 0, "Hello Excel", format1);
// Change the row height
worksheet1.setRow(0, 20);
// Change the column width
worksheet1.setColumn(0, 0, 15);
// Add an other worksheet with a user defined sheet name.
var worksheet2 = writer.addWorksheet("Worksheet2");
// Write some data to the worksheet.
writeWorksheetData(worksheet2);
// Create a chart object.
var chart = writer.addChart(writer.CHART_COLUMN);
// Configure the chart. In simplest case we just add some value data
// series. The empty categories will default to 1 to 5 like in Excel.
var series1 = chart.addSeries("", "=Worksheet2!$A$1:$A$5");
var series2 = chart.addSeries("", "=Worksheet2!$B$1:$B$5");
var series3 = chart.addSeries("", "=Worksheet2!$C$1:$C$5");
// Insert the chart into the worksheet
worksheet2.insertChart(6, 1, chart);
// Save the file.
if (!writer.save())
throw writer.getLastError();
function writeWorksheetData(worksheet)
{
var data = [
// Three columns of data.
[1, 2, 3],
[2, 4, 6],
[3, 6, 9],
[4, 8, 12],
[5, 10, 15]
];
var row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet.writeCell("number", row, col, data[row][col]);
}

Constructor & Destructor Documentation

◆ XLSXWriter()

XLSXWriter XLSXWriter::XLSXWriter ( String  filename)

Create a new XLSXWriter object with a given filename.

Parameters
filenameThe name of the new Excel file to create.
Returns
An XLSXWriter instance
Note
When specifying a filename it is recommended that you use an .xlsx extension or Excel will generate a warning when opening the file.
Since
DOCUMENTS 5.0e

Member Function Documentation

◆ activateChartsheet()

boolean XLSXWriter::activateChartsheet ( var  chartsheet)

Make a chartsheet the active, i.e., visible chartsheet.

This function is used to specify which chartsheet is initially visible in a multi-sheet Excel document.

Parameters
chartsheetThe chartsheet to be updated can be specified as follows:
  • String containing the chartsheet name.
  • XLSXChartsheet object representing the chartsheet.
Returns
true if successful, false in case of any error
Note
More than one chartsheet can be selected via the XLSXWriter.selectChartsheet(var chartsheet) function, however only one chartsheet can be active.
Since
DOCUMENTS 5.0e
Example:
writer.activateChartsheet(chartsheet2);
See also
XLSXWriter.activateWorksheet(var worksheet)

◆ activateWorksheet()

boolean XLSXWriter::activateWorksheet ( var  worksheet)

Make a worksheet the active, i.e., visible worksheet.

This function is used to specify which worksheet is initially visible in a multi-sheet Excel document.

Parameters
worksheetThe worksheet to be updated can be specified as follows:
  • String containing the worksheet name.
  • XLSXWorksheet object representing the worksheet.
Returns
true if successful, false in case of any error
Note
More than one worksheet can be selected via the XLSXWriter.selectWorksheet(var worksheet) function, however only one worksheet can be active. The default active worksheet is the first worksheet.
Since
DOCUMENTS 5.0e
Example:
writer.activateWorksheet(worksheet2);
See also
XLSXWriter.activateChartsheet(var chartsheet)

◆ addChart()

XLSXChart XLSXWriter::addChart ( number  type)

Create a new chart to be added to a worksheet/chartsheet.

Parameters
typeThe type (from 'Chart types') of chart to be created.
Returns
An XLSXChart object if successful, null in case of any error.
Since
DOCUMENTS 5.0e
Example:
// Create a chart object.
var chart = writer.addChart(writer.CHART_COLUMN);
// Add data series to the chart.
chart.addSeries(NULL, "Worksheet2!$A$1:$A$5");
chart.addSeries(NULL, "Worksheet2!$B$1:$B$5");
chart.addSeries(NULL, "Worksheet2!$C$1:$C$5");
// Insert the chart into the worksheet
worksheet2.insertChart(6, 1, chart);

◆ addChartsheet()

XLSXChartsheet XLSXWriter::addChartsheet ( String  name = "")

Add a new chartsheet to the current Excel document.

Parameters
nameOptional chartsheet name. If it is empty the default Excel convention will be followed, i.e. Chart1, Chart2, etc. The chartsheet name must be a valid Excel chartsheet name, i.e. it must be less than 32 character and it cannot contain any of the characters: / \ [ ] : * ?
In addition, you cannot use the same, case insensitive, sheetname for more than one worksheet, or chartsheet.
Returns
An XLSXChartsheet object if successful, null in case of any error.
Note
At least one worksheet should be added to a new Excel file when creating a chartsheet in order to provide data for the chart.
Since
DOCUMENTS 5.0e
Example:
var worksheet1 = writer.addWorksheet("Worksheet1");
var chartsheet1 = writer.addChartsheet("Chartsheet1");

◆ addFormat()

XLSXWorksheet XLSXWriter::addFormat ( String  name)

Create a new format object to format cells in worksheets.

Parameters
nameUnique format name.
Returns
An XLSXFormat object if successful, null in case of any error.
Since
DOCUMENTS 5.0e
Example:
// Create the Format.
var format1 = writer.addFormat("format1");
// Set some of the format properties.
format1.setFontStyle("bold");
format1.setFontColor(writer.COLOR_RED); // see Predefined values for common colors
// Use the format to change the text format in a cell.
worksheet1.writeCell("string", 0, 0, "Hello", format1);

◆ addWorksheet()

XLSXWorksheet XLSXWriter::addWorksheet ( String  name = "")

Add a new worksheet to the current Excel document.

Parameters
nameOptional worksheet name. If it is empty the default Excel convention will be followed, i.e. Sheet1, Sheet2, etc. The worksheet name must be a valid Excel worksheet name, i.e. it must be less than 32 character and it cannot contain any of the characters: / \ [ ] : * ?
In addition, you cannot use the same, case insensitive, sheetname for more than one worksheet, or chartsheet.
Returns
An XLSXWorksheet object if successful, null in case of any error.
Note
At least one worksheet should be added to a new Excel file.
Since
DOCUMENTS 5.0e
Example:
var worksheet1 = writer.addWorksheet("Worksheet1");

◆ getChartsheetByName()

XLSXChartsheet XLSXWriter::getChartsheetByName ( String  name)

Get a chartsheet object from its name.

Parameters
nameChartsheet name.
Returns
An XLSXChartsheet object if successful, null in case of any error.
Since
DOCUMENTS 5.0e
Example:
var chartsheet1 = writer.getChartsheetByName("Chartsheet1");

◆ getFilePath()

String XLSXWriter::getFilePath ( )

Get the file path of the created Excel file.

Returns
The file path as String.
Since
DOCUMENTS 5.0e
Example:
util.out(writer.getFilePath());

◆ getLastError()

String XLSXWriter::getLastError ( )

Function to get the description of the last error that occurred.

Returns
Text of the last error as String
Since
DOCUMENTS 5.0e

◆ getWorksheetByName()

XLSXWorksheet XLSXWriter::getWorksheetByName ( String  name)

Get a worksheet object from its name.

Parameters
nameWorksheet name.
Returns
An XLSXWorksheet object if successful, null in case of any error.
Since
DOCUMENTS 5.0e
Example:
var worksheet1 = writer.getWorksheetByName("Worksheet1");

◆ hideChartsheet()

boolean XLSXWriter::hideChartsheet ( var  chartsheet)

Hide the given chartsheet.

Parameters
chartsheetThe chartsheet to be updated can be specified as follows:
  • String containing the chartsheet name.
  • XLSXChartsheet object representing the chartsheet.
Returns
true if successful, false in case of any error
Note
A hidden chartsheet can not be activated or selected so this function is mutually exclusive with the XLSXWriter.activateChartsheet(var chartsheet) and XLSXWriter.selectChartsheet(var chartsheet) functions.
Since
DOCUMENTS 5.0e
Example:
writer.activateChartsheet(chartsheet2);
writer.hideChartsheet(chartsheet1);
See also
XLSXWriter.hideWorksheet(var worksheet)

◆ hideWorksheet()

boolean XLSXWriter::hideWorksheet ( var  worksheet)

Hide the given worksheet.

Parameters
worksheetThe worksheet to be updated can be specified as follows:
  • String containing the worksheet name.
  • XLSXWorksheet object representing the worksheet.
Returns
true if successful, false in case of any error
Note
A hidden worksheet can not be activated or selected so this function is mutually exclusive with the XLSXWriter.activateWorksheet(var worksheet) and XLSXWriter.selectWorksheet(var worksheet) functions. In addition, since the first worksheet will default to being the active worksheet, you cannot hide the first worksheet without activating another sheet.
Since
DOCUMENTS 5.0e
Example:
writer.hideWorksheet(worksheet2);
See also
XLSXWriter.hideChartsheet(var chartsheet)

◆ save()

boolean XLSXWriter::save ( )

Write the Excel file to disk and free any memory allocated internally to the Excel file.

Note
After calling this function only both functions XLSXWriter.getFilePath() and XLSXWriter.getLastError() are available for the XLSXWriter object.
Returns
true if successful, false in case of any error
Since
DOCUMENTS 5.0e
Example:
if (!writer.save())
util.out(writer.getLastError());

◆ selectChartsheet()

boolean XLSXWriter::selectChartsheet ( var  chartsheet)

Set a chartsheet tab as selected.

This function is used to indicate that a chartsheet is selected in a multi-sheet Excel document.

Parameters
chartsheetThe chartsheet to be updated can be specified as follows:
  • String containing the chartsheet name.
  • XLSXChartsheet object representing the chartsheet.
Returns
true if successful, false in case of any error
Note
A selected chartsheet has its tab highlighted. Selecting chartsheets is a way of grouping them together so that, for example, several chartsheets could be printed in one go. A chartsheet that has been activated via the XLSXWriter.activateChartsheet(var chartsheet) function will also appear as selected.
Since
DOCUMENTS 5.0e
Example:
writer.selectChartsheet("Chartsheet2");
See also
XLSXWriter.selectWorksheet(var worksheet)

◆ selectWorksheet()

boolean XLSXWriter::selectWorksheet ( var  worksheet)

Set a worksheet tab as selected.

This function is used to indicate that a worksheet is selected in a multi-sheet Excel document.

Parameters
worksheetThe worksheet to be updated can be specified as follows:
  • String containing the worksheet name.
  • XLSXWorksheet object representing the worksheet.
Returns
true if successful, false in case of any error
Note
A selected worksheet has its tab highlighted. Selecting worksheets is a way of grouping them together so that, for example, several worksheets could be printed in one go. A worksheet that has been activated via the XLSXWriter.activateWorksheet(var worksheet) function will also appear as selected.
Since
DOCUMENTS 5.0e
Example:
writer.selectWorksheet(worksheet2);
See also
XLSXWriter.selectChartsheet(var chartsheet)

◆ setProperties()

boolean XLSXWriter::setProperties ( String  title,
String  subject,
String  author,
String  manager,
String  company,
String  category,
String  keywords,
String  comments,
String  status,
String  hyperlinkBase 
)

Set the document properties.

This function can be used to set the document properties of the current Excel document. These properties are visible in Excel (e.g. under File -> Information -> Properties in Excel 2013) and are also available to external applications that read or index windows files.

Parameters
titleTitle of the Excel document.
subjectOptional subject of the Excel document.
authorOptional author of the Excel document.
managerOptional manager field of the Excel document.
companyOptional company field of the Excel document.
categoryOptional category of the Excel document.
keywordsOptional keywords of the Excel document.
commentsOptional comment of the Excel document.
statusOptional status of the Excel document.
hyperlinkBaseOptional hyperlink base url of the Excel document.
Returns
true if successful, false in case of any error
Since
DOCUMENTS 5.0e
Example:
writer.setProperties("This is an example spreadsheet");

Member Data Documentation

◆ version

String XLSXWriter::version

String value containing the version number of the used library Libxlsxwriter.

Returns
String value containing the version number.
Since
DOCUMENTS 5.0e

This documentation refers DOCUMENTS 5.0e (2105).
Created at 11-09-2019. - © 1998-2019 otris software AG, Königswall 21, D-44137 Dortmund. support@otris.de