Struct xlsxwriter::worksheet::Worksheet
source · pub struct Worksheet<'a> { /* private fields */ }
Expand description
The Worksheet object represents an Excel worksheet. It handles operations such as writing data to cells or formatting worksheet layout.
A Worksheet object isn’t created directly. Instead a worksheet is created by calling the workbook.add_worksheet()
function from a Workbook object:
use xlsxwriter::prelude::*;
let workbook = Workbook::new("test-worksheet.xlsx")?;
let mut worksheet = workbook.add_worksheet(None)?;
worksheet.write_string(0, 0, "Hello, excel", None)?;
workbook.close()
Please read original libxlsxwriter document for description missing functions. Most of this document is based on libxlsxwriter document.
Implementations§
source§impl<'a> Worksheet<'a>
impl<'a> Worksheet<'a>
pub fn conditional_format_cell( &mut self, row: WorksheetRow, col: WorksheetCol, conditional_format: &ConditionalFormat ) -> Result<(), XlsxError>
pub fn conditional_format_range( &mut self, first_row: WorksheetRow, first_col: WorksheetCol, last_row: WorksheetRow, last_col: WorksheetCol, conditional_format: &ConditionalFormat ) -> Result<(), XlsxError>
source§impl<'a> Worksheet<'a>
impl<'a> Worksheet<'a>
sourcepub fn autofilter(
&mut self,
first_row: WorksheetRow,
first_col: WorksheetCol,
last_row: WorksheetRow,
last_col: WorksheetCol
) -> Result<(), XlsxError>
pub fn autofilter( &mut self, first_row: WorksheetRow, first_col: WorksheetCol, last_row: WorksheetRow, last_col: WorksheetCol ) -> Result<(), XlsxError>
This function allows an autofilter to be added to a worksheet.
An autofilter is a way of adding drop down lists to the headers of a 2D range of worksheet data. This allows users to filter the data based on simple criteria so that some data is shown and some is hidden.
sourcepub fn filter_column(
&mut self,
col: WorksheetCol,
rule: &FilterRule
) -> Result<(), XlsxError>
pub fn filter_column( &mut self, col: WorksheetCol, rule: &FilterRule ) -> Result<(), XlsxError>
This function can be used to filter columns in a autofilter range based on single rule conditions.
use xlsxwriter::prelude::*;
worksheet.autofilter(0, 0, 10, 1)?;
worksheet.filter_column(0, &FilterRule::new(FilterCriteria::NotEqualTo, 9.0))?;
worksheet.set_row_opt(9, LXW_DEF_ROW_HEIGHT, None, &RowColOptions::new(true, 0, false))?;
The col
parameter is a zero indexed column number and must refer to a column in an existing autofilter created with Worksheet::autofilter
.
It isn’t sufficient to just specify the filter condition. You must also hide any rows that don’t match the filter condition.
sourcepub fn filter_column2(
&mut self,
col: WorksheetCol,
rule1: &FilterRule,
rule2: &FilterRule,
and_or: FilterOperator
) -> Result<(), XlsxError>
pub fn filter_column2( &mut self, col: WorksheetCol, rule1: &FilterRule, rule2: &FilterRule, and_or: FilterOperator ) -> Result<(), XlsxError>
This function can be used to filter columns in a autofilter range based on two rule conditions.
use xlsxwriter::prelude::*;
worksheet.autofilter(0, 0, 10, 1)?;
worksheet.filter_column2(0, &FilterRule::new(FilterCriteria::LessThan, 8.5), &FilterRule::new(FilterCriteria::GreaterThan, 9.5), FilterOperator::FilterOr)?;
worksheet.set_row_opt(9, LXW_DEF_ROW_HEIGHT, None, &RowColOptions::new(true, 0, false))?;
It isn’t sufficient to just specify the filter condition. You must also hide any rows that don’t match the filter condition.
sourcepub fn filter_list(
&mut self,
col: WorksheetCol,
list: &[&str]
) -> Result<(), XlsxError>
pub fn filter_list( &mut self, col: WorksheetCol, list: &[&str] ) -> Result<(), XlsxError>
This function can be used specify multiple string matching criteria. This is a newer type of filter introduced in Excel 2007.
Prior to that it was only possible to have either 1 or 2 filter conditions, such as the ones used by Worksheet::filter_column()
and Worksheet::filter_column2()
.
use xlsxwriter::prelude::*;
worksheet.autofilter(0, 0, 10, 1)?;
worksheet.filter_list(0, &["1", "2", "3", "4", "5", "6", "7", "8", "10"])?;
worksheet.set_row_opt(9, LXW_DEF_ROW_HEIGHT, None, &RowColOptions::new(true, 0, false))?;
It isn’t sufficient to just specify the filter condition. You must also hide any rows that don’t match the filter condition.
source§impl<'a> Worksheet<'a>
impl<'a> Worksheet<'a>
sourcepub fn add_table(
&mut self,
first_row: WorksheetRow,
first_col: WorksheetCol,
last_row: WorksheetRow,
last_col: WorksheetCol,
options: Option<TableOptions>
) -> Result<(), XlsxError>
pub fn add_table( &mut self, first_row: WorksheetRow, first_col: WorksheetCol, last_row: WorksheetRow, last_col: WorksheetCol, options: Option<TableOptions> ) -> Result<(), XlsxError>
This function is used to add a table to a worksheet. Tables in Excel are a way of grouping a range of cells into a single entity that has common formatting or that can be referenced from formulas. Tables can have column headers, autofilters, total rows, column formulas and default formatting.
worksheet.write_string(0, 0, "header 1", None)?;
worksheet.write_string(0, 1, "header 2", None)?;
worksheet.write_string(1, 0, "content 1", None)?;
worksheet.write_number(1, 1, 1.0, None)?;
worksheet.write_string(2, 0, "content 2", None)?;
worksheet.write_number(2, 1, 2.0, None)?;
worksheet.write_string(3, 0, "content 3", None)?;
worksheet.write_number(3, 1, 3.0, None)?;
worksheet.add_table(0, 0, 3, 1, None)?;
Please read libxslxwriter document to learn more.
source§impl<'a> Worksheet<'a>
impl<'a> Worksheet<'a>
sourcepub fn data_validation_cell(
&mut self,
row: WorksheetRow,
col: WorksheetCol,
validation: &DataValidation
) -> Result<(), XlsxError>
pub fn data_validation_cell( &mut self, row: WorksheetRow, col: WorksheetCol, validation: &DataValidation ) -> Result<(), XlsxError>
This function is used to construct an Excel data validation or to limit the user input to a dropdown list of values
let validation = DataValidation::new(
DataValidationType::Integer {
number_options: DataValidationNumberOptions::GreaterThanOrEqualTo(10),
ignore_blank: true
},
None,
Some(ErrorAlertOptions {
style: DataValidationErrorType::Warning,
title: String::new(),
message: String::new()
})
);
worksheet.write_string(0, 0, "10 or greater", None)?;
worksheet.data_validation_cell(1, 0, &validation)?;
sourcepub fn data_validation_range(
&mut self,
first_row: WorksheetRow,
first_col: WorksheetCol,
last_row: WorksheetRow,
last_col: WorksheetCol,
validation: &DataValidation
) -> Result<(), XlsxError>
pub fn data_validation_range( &mut self, first_row: WorksheetRow, first_col: WorksheetCol, last_row: WorksheetRow, last_col: WorksheetCol, validation: &DataValidation ) -> Result<(), XlsxError>
The this function is the same as the data_validation_cell()
, see above, except the data validation is applied to a range of cells.
let validation = DataValidation::new(
DataValidationType::List {
values: vec!["VALUE1".to_string(), "VALUE2".to_string(), "VALUE3".to_string()],
dropdown: true,
ignore_blank: true
},
None,
None
);
worksheet.data_validation_range(0, 0, 100, 100, &validation)?;
source§impl<'a> Worksheet<'a>
impl<'a> Worksheet<'a>
sourcepub fn write_comment(
&mut self,
row: WorksheetRow,
col: WorksheetCol,
text: &str
) -> Result<(), XlsxError>
pub fn write_comment( &mut self, row: WorksheetRow, col: WorksheetCol, text: &str ) -> Result<(), XlsxError>
This function writes the comment of a cell
worksheet.write_comment(0, 0, "This is some comment text")?;
worksheet.write_comment(1, 0, "This cell also has a comment")?;
pub fn write_comment_opt( &mut self, row: WorksheetRow, col: WorksheetCol, text: &str, options: &CommentOptions ) -> Result<(), XlsxError>
sourcepub fn write_number(
&mut self,
row: WorksheetRow,
col: WorksheetCol,
number: f64,
format: Option<&Format>
) -> Result<(), XlsxError>
pub fn write_number( &mut self, row: WorksheetRow, col: WorksheetCol, number: f64, format: Option<&Format> ) -> Result<(), XlsxError>
This function writes numeric types to the cell specified by row and column:
worksheet.write_number(0, 0, 123456.0, None)?;
worksheet.write_number(1, 0, 2.3451, None)?;
The native data type for all numbers in Excel is a IEEE-754 64-bit double-precision floating point, which is also the default type used by worksheet_write_number
.
The format parameter is used to apply formatting to the cell. This parameter can be None
to indicate no formatting or it can be a Format object.
worksheet.write_number(0, 0, 1234.567, Some(&Format::new().set_num_format("$#,##0.00")))?;
Note
Excel doesn’t support NaN, Inf or -Inf as a number value. If you are writing data that contains these values then your application should convert them to a string or handle them in some other way.
sourcepub fn write_string(
&mut self,
row: WorksheetRow,
col: WorksheetCol,
text: &str,
format: Option<&Format>
) -> Result<(), XlsxError>
pub fn write_string( &mut self, row: WorksheetRow, col: WorksheetCol, text: &str, format: Option<&Format> ) -> Result<(), XlsxError>
This function writes a string to the cell specified by row and column:
worksheet.write_string(0, 0, "This phrase is English!", None)?;
The format parameter is used to apply formatting to the cell. This parameter can be None
to indicate no formatting or it can be a Format object:
worksheet.write_string(0, 0, "This phrase is Bold!", Some(&Format::new().set_bold()))?;
Unicode strings are supported in UTF-8 encoding.
worksheet.write_string(0, 0, "こんにちは、世界!", None)?;
sourcepub fn write_formula(
&mut self,
row: WorksheetRow,
col: WorksheetCol,
formula: &str,
format: Option<&Format>
) -> Result<(), XlsxError>
pub fn write_formula( &mut self, row: WorksheetRow, col: WorksheetCol, formula: &str, format: Option<&Format> ) -> Result<(), XlsxError>
This function writes a formula or function to the cell specified by row and column:
worksheet.write_formula(0, 0, "=B3 + 6", None)?;
worksheet.write_formula(1, 0, "=SIN(PI()/4)", None)?;
worksheet.write_formula(2, 0, "=SUM(A1:A2)", None)?;
worksheet.write_formula(3, 0, "=IF(A3>1,\"Yes\", \"No\")", None)?;
worksheet.write_formula(4, 0, "=AVERAGE(1, 2, 3, 4)", None)?;
worksheet.write_formula(5, 0, "=DATEVALUE(\"1-Jan-2013\")", None)?;
The format
parameter is used to apply formatting to the cell. This parameter can be None
to indicate no formatting or it can be a Format object.
Libxlsxwriter doesn’t calculate the value of a formula and instead stores a default value of 0
. The correct formula result is displayed in Excel, as shown in the example above, since it recalculates the formulas when it loads the file. For cases where this is an issue see the write_formula_num()
function and the discussion in that section.
Formulas must be written with the US style separator/range operator which is a comma (not semi-colon). Therefore a formula with multiple values should be written as follows:
// OK
worksheet.write_formula(0, 0, "=SUM(1, 2, 3)", None)?;
// NO. Error on load.
worksheet.write_formula(1, 0, "=SUM(1; 2; 3)", None)?;
See also Working with Formulas.
sourcepub fn write_array_formula(
&mut self,
first_row: WorksheetRow,
first_col: WorksheetCol,
last_row: WorksheetRow,
last_col: WorksheetCol,
formula: &str,
format: Option<&Format>
) -> Result<(), XlsxError>
pub fn write_array_formula( &mut self, first_row: WorksheetRow, first_col: WorksheetCol, last_row: WorksheetRow, last_col: WorksheetCol, formula: &str, format: Option<&Format> ) -> Result<(), XlsxError>
This function writes an array formula to a cell range. In Excel an array formula is a formula that performs a calculation on a set of values.
In Excel an array formula is indicated by a pair of braces around the formula: {=SUM(A1:B1*A2:B2)}
.
Array formulas can return a single value or a range or values. For array formulas that return a range of values you must specify the range that the return values will be written to. This is why this function has first_ and last_ row/column parameters:
worksheet.write_array_formula(4, 0, 6, 0, "{=TREND(C5:C7,B5:B7)}", None)?;
If the array formula returns a single value then the first_ and last_ parameters should be the same:
worksheet.write_array_formula(1, 0, 1, 0, "{=SUM(B1:C1*B2:C2)}", None)?;
sourcepub fn write_datetime(
&mut self,
row: WorksheetRow,
col: WorksheetCol,
datetime: &DateTime,
format: Option<&Format>
) -> Result<(), XlsxError>
pub fn write_datetime( &mut self, row: WorksheetRow, col: WorksheetCol, datetime: &DateTime, format: Option<&Format> ) -> Result<(), XlsxError>
This function can be used to write a date or time to the cell specified by row and column:
use xlsxwriter::prelude::*;
let datetime = DateTime::new(2013, 2, 28, 12, 0, 0.0);
worksheet.write_datetime(1, 0, &datetime, Some(&Format::new().set_num_format("mmm d yyyy hh:mm AM/PM")))?;
The format
parameter should be used to apply formatting to the cell using a Format
object as shown above. Without a date format the datetime will appear as a number only.
See Working with Dates and Times for more information about handling dates and times in libxlsxwriter.
sourcepub fn write_url(
&mut self,
row: WorksheetRow,
col: WorksheetCol,
url: &str,
format: Option<&Format>
) -> Result<(), XlsxError>
pub fn write_url( &mut self, row: WorksheetRow, col: WorksheetCol, url: &str, format: Option<&Format> ) -> Result<(), XlsxError>
This function is used to write a URL/hyperlink to a worksheet cell specified by row and column.
The format parameter is used to apply formatting to the cell. This parameter can be None
to indicate no formatting or it can be a Format object. The typical worksheet format for a hyperlink is a blue underline:
let mut url_format = Format::new();
url_format.set_underline(FormatUnderline::Single).set_font_color(FormatColor::Blue);
worksheet.write_url(0, 0, "http://libxlsxwriter.github.io", Some(&url_format))?;
The usual web style URI’s are supported: http://
, https://
, ftp://
and mailto:
:
worksheet.write_url(0, 0, "ftp://www.python.org/", Some(&url_format))?;
worksheet.write_url(1, 0, "http://www.python.org/", Some(&url_format))?;
worksheet.write_url(2, 0, "https://www.python.org/", Some(&url_format))?;
worksheet.write_url(3, 0, "mailto:foo@example.com", Some(&url_format))?;
An Excel hyperlink is comprised of two elements: the displayed string and the non-displayed link. By default the displayed string is the same as the link. However, it is possible to overwrite it with any other libxlsxwriter type using the appropriate Worksheet.write_*()
function. The most common case is to overwrite the displayed link text with another string:
worksheet.write_url(0, 0, "http://libxlsxwriter.github.io", Some(&url_format))?;
worksheet.write_string(0, 0, "Read the documentation.", Some(&url_format))?;
Two local URIs are supported: internal:
and external:
. These are used for hyperlinks to internal worksheet references or external workbook and worksheet references:
worksheet.write_url(0, 0, "internal:Sheet2!A1", Some(&url_format))?;
worksheet.write_url(1, 0, "internal:Sheet2!B2", Some(&url_format))?;
worksheet.write_url(2, 0, "internal:Sheet2!A1:B2", Some(&url_format))?;
worksheet.write_url(3, 0, "internal:'Sales Data'!A1", Some(&url_format))?;
worksheet.write_url(4, 0, "external:c:\\temp\\foo.xlsx", Some(&url_format))?;
worksheet.write_url(5, 0, "external:c:\\foo.xlsx#Sheet2!A1", Some(&url_format))?;
worksheet.write_url(6, 0, "external:..\\foo.xlsx", Some(&url_format))?;
worksheet.write_url(7, 0, "external:..\\foo.xlsx#Sheet2!A1", Some(&url_format))?;
worksheet.write_url(8, 0, "external:\\\\NET\\share\\foo.xlsx", Some(&url_format))?;
sourcepub fn write_boolean(
&mut self,
row: WorksheetRow,
col: WorksheetCol,
value: bool,
format: Option<&Format>
) -> Result<(), XlsxError>
pub fn write_boolean( &mut self, row: WorksheetRow, col: WorksheetCol, value: bool, format: Option<&Format> ) -> Result<(), XlsxError>
Write an Excel boolean to the cell specified by row and column:
worksheet.write_boolean(0, 0, true, None)?;
worksheet.write_boolean(1, 0, false, None)?;
sourcepub fn write_blank(
&mut self,
row: WorksheetRow,
col: WorksheetCol,
format: Option<&Format>
) -> Result<(), XlsxError>
pub fn write_blank( &mut self, row: WorksheetRow, col: WorksheetCol, format: Option<&Format> ) -> Result<(), XlsxError>
Write a blank cell specified by row and column:
worksheet.write_blank(1, 1, None);
This function is used to add formatting to a cell which doesn’t contain a string or number value.
Excel differentiates between an “Empty” cell and a “Blank” cell. An Empty cell is a cell which doesn’t contain data or formatting whilst a Blank cell doesn’t contain data but does contain formatting. Excel stores Blank cells but ignores Empty cells.
As such, if you write an empty cell without formatting it is ignored.
sourcepub fn write_formula_num(
&mut self,
row: WorksheetRow,
col: WorksheetCol,
formula: &str,
format: Option<&Format>,
number: f64
) -> Result<(), XlsxError>
pub fn write_formula_num( &mut self, row: WorksheetRow, col: WorksheetCol, formula: &str, format: Option<&Format>, number: f64 ) -> Result<(), XlsxError>
This function writes a formula or Excel function to the cell specified by row and column with a user defined numeric result:
worksheet.write_formula_num(1, 1, "=1 + 2", None, 3.0);
Libxlsxwriter doesn’t calculate the value of a formula and instead stores the value 0 as the formula result. It then sets a global flag in the XLSX file to say that all formulas and functions should be recalculated when the file is opened.
This is the method recommended in the Excel documentation and in general it works fine with spreadsheet applications.
However, applications that don’t have a facility to calculate formulas, such as Excel Viewer, or some mobile applications will only display the 0 results.
If required, the worksheet_write_formula_num
function can be used to specify a formula and its result.
This function is rarely required and is only provided for compatibility with some third party applications.
For most applications the worksheet_write_formula
function is the recommended way of writing formulas.
sourcepub fn write_formula_str(
&mut self,
row: WorksheetRow,
col: WorksheetCol,
formula: &str,
format: Option<&Format>,
result: &str
) -> Result<(), XlsxError>
pub fn write_formula_str( &mut self, row: WorksheetRow, col: WorksheetCol, formula: &str, format: Option<&Format>, result: &str ) -> Result<(), XlsxError>
This function writes a formula or Excel function to the cell specified by row and column with a user defined string result:
worksheet.write_formula_str(1, 1, "=\"A\" & \"B\"", None, "AB");
The worksheet_write_formula_str
function is similar to the worksheet_write_formula_num
function except it
writes a string result instead or a numeric result. See worksheet_write_formula_num
for more details on
why/when these functions are required.
One place where the worksheet_write_formula_str
function may be required is to specify an empty result which
will force a recalculation of the formula when loaded in LibreOffice.
sourcepub fn write_rich_string(
&mut self,
row: WorksheetRow,
col: WorksheetCol,
text: &[(&str, Option<&Format>)],
format: Option<&Format>
) -> Result<(), XlsxError>
pub fn write_rich_string( &mut self, row: WorksheetRow, col: WorksheetCol, text: &[(&str, Option<&Format>)], format: Option<&Format> ) -> Result<(), XlsxError>
This function is used to write strings with multiple formats. For example to write the string ‘This is bold and this is italic’ you would use the following:
worksheet.write_rich_string(
0, 0,
&[
("This is ", None),
("bold", Some(&Format::new().set_bold())),
(" and this is ", None),
("italic", Some(&Format::new().set_italic()))
],
None
)?;
The basic rule is to break the string into fragments and put a lxw_format
object before the fragment that you want to format. So if we look at the above example again:
This is bold and this is italic
The would be broken down into 4 fragments:
default: |This is |
bold: |bold|
default: | and this is |
italic: |italic|
This in then converted to the tuple fragments shown in the example above. For the default format we use None.
Note
Excel doesn’t allow the use of two consecutive formats in a rich string or an empty string fragment. For either of these conditions a warning is raised and the input to worksheet.write_rich_string()
is ignored.
pub fn set_row( &mut self, row: WorksheetRow, height: f64, format: Option<&Format> ) -> Result<(), XlsxError>
pub fn set_row_opt( &mut self, row: WorksheetRow, height: f64, format: Option<&Format>, options: &RowColOptions ) -> Result<(), XlsxError>
sourcepub fn set_row_pixels(
&mut self,
row: WorksheetRow,
pixels: u32,
format: Option<&Format>
) -> Result<(), XlsxError>
pub fn set_row_pixels( &mut self, row: WorksheetRow, pixels: u32, format: Option<&Format> ) -> Result<(), XlsxError>
The set_row_pixels
function is the same as the Worksheet::set_row
function except that the height can be set in pixels.
If you wish to set the format of a row without changing the height you can pass the default row height in pixels: LXW_DEF_ROW_HEIGHT_PIXELS
.
pub fn set_row_pixels_opt( &mut self, row: WorksheetRow, pixels: u32, format: Option<&Format>, options: &RowColOptions ) -> Result<(), XlsxError>
pub fn set_column( &mut self, first_col: WorksheetCol, last_col: WorksheetCol, width: f64, format: Option<&Format> ) -> Result<(), XlsxError>
pub fn set_column_opt( &mut self, first_col: WorksheetCol, last_col: WorksheetCol, width: f64, format: Option<&Format>, options: &RowColOptions ) -> Result<(), XlsxError>
pub fn set_column_pixels( &mut self, first_col: WorksheetCol, last_col: WorksheetCol, pixels: u32, format: Option<&Format> ) -> Result<(), XlsxError>
pub fn set_column_pixels_opt( &mut self, first_col: WorksheetCol, last_col: WorksheetCol, pixels: u32, format: Option<&Format>, options: &mut RowColOptions ) -> Result<(), XlsxError>
sourcepub fn insert_image(
&mut self,
row: WorksheetRow,
col: WorksheetCol,
filename: &str
) -> Result<(), XlsxError>
pub fn insert_image( &mut self, row: WorksheetRow, col: WorksheetCol, filename: &str ) -> Result<(), XlsxError>
This function can be used to insert a image into a worksheet. The image can be in PNG, JPEG or BMP format:
worksheet.insert_image(2, 1, "../images/simple1.png")?;
The Worksheet.insert_image_opt
function takes additional optional parameters to position and scale the image, see below.
Note
The scaling of a image may be affected if is crosses a row that has its default height changed due to a font that is larger than
the default font size or that has text wrapping turned on. To avoid this you should explicitly set the height of the row using
Worksheet::set_row
if it crosses an inserted image.
BMP images are only supported for backward compatibility. In general it is best to avoid BMP images since they aren’t compressed. If used, BMP images must be 24 bit, true color, bitmaps.
sourcepub fn insert_image_opt(
&mut self,
row: WorksheetRow,
col: WorksheetCol,
filename: &str,
opt: &ImageOptions
) -> Result<(), XlsxError>
pub fn insert_image_opt( &mut self, row: WorksheetRow, col: WorksheetCol, filename: &str, opt: &ImageOptions ) -> Result<(), XlsxError>
This function is like Worksheet.insert_image
function except that it takes an optional ImageOptions
struct to scale and position the image:
worksheet.insert_image_opt(
2, 1,
"../images/simple1.png",
&ImageOptions{
x_offset: 30,
y_offset: 30,
x_scale: 0.5,
y_scale: 0.5,
}
)?;
Note
See the notes about row scaling and BMP images in Worksheet::insert_image
above.
sourcepub fn insert_image_buffer(
&mut self,
row: WorksheetRow,
col: WorksheetCol,
buffer: &[u8]
) -> Result<(), XlsxError>
pub fn insert_image_buffer( &mut self, row: WorksheetRow, col: WorksheetCol, buffer: &[u8] ) -> Result<(), XlsxError>
This function can be used to insert a image into a worksheet from a memory buffer:
let data = include_bytes!("../../../images/simple1.png");
worksheet.insert_image_buffer(0, 0, &data[..])?;
See Worksheet::insert_image
for details about the supported image formats, and other image features.
pub fn insert_image_buffer_opt( &mut self, row: WorksheetRow, col: WorksheetCol, buffer: &[u8], opt: &ImageOptions ) -> Result<(), XlsxError>
pub fn insert_chart( &mut self, row: WorksheetRow, column: WorksheetCol, chart: &Chart<'_> ) -> Result<(), XlsxError>
sourcepub fn merge_range(
&mut self,
first_row: WorksheetRow,
first_col: WorksheetCol,
last_row: WorksheetRow,
last_col: WorksheetCol,
string: &str,
format: Option<&Format>
) -> Result<(), XlsxError>
pub fn merge_range( &mut self, first_row: WorksheetRow, first_col: WorksheetCol, last_row: WorksheetRow, last_col: WorksheetCol, string: &str, format: Option<&Format> ) -> Result<(), XlsxError>
The Worksheet::merge_range
function allows cells to be merged together so that they act as a single area.
sourcepub fn activate(&mut self)
pub fn activate(&mut self)
The Worksheet::activate
function is used to specify which worksheet is initially visible in a multi-sheet workbook.
sourcepub fn select(&mut self)
pub fn select(&mut self)
The Worksheet::select
function is used to indicate that a worksheet is selected in a multi-sheet workbook.
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 Worksheet::activate
function will also appear as selected.
sourcepub fn hide(&mut self)
pub fn hide(&mut self)
The Worksheet::hide
function is used to hide a worksheet.
You may wish to hide a worksheet in order to avoid confusing a user with intermediate data or calculations.
A hidden worksheet can not be activated or selected so this function is mutually exclusive with the Worksheet::activate
and Worksheet::select
functions. In addition, since the first worksheet will default to being the active worksheet,
you cannot hide the first worksheet without activating another sheet.
sourcepub fn set_first_sheet(&mut self)
pub fn set_first_sheet(&mut self)
The Worksheet::activate
function determines which worksheet is initially selected. However,
if there are a large number of worksheets the selected worksheet may not appear on the screen.
To avoid this you can select the leftmost visible worksheet tab using Worksheet::set_first_sheet
This function is not required very often. The default value is the first worksheet.
sourcepub fn freeze_panes(&mut self, row: WorksheetRow, col: WorksheetCol)
pub fn freeze_panes(&mut self, row: WorksheetRow, col: WorksheetCol)
The Worksheet::freeze_panes
function can be used to divide a worksheet into horizontal or
vertical regions known as panes and to “freeze” these panes so that the splitter bars are not visible.
The parameters row and col are used to specify the location of the split. It should be noted that the split is specified at the top or left of a cell and that the function uses zero based indexing. Therefore to freeze the first row of a worksheet it is necessary to specify the split at row 2 (which is 1 as the zero-based index).
You can set one of the row and col parameters as zero if you do not want either a vertical or horizontal split.
sourcepub fn split_panes(&mut self, vertical: f64, horizontal: f64)
pub fn split_panes(&mut self, vertical: f64, horizontal: f64)
The Worksheet::split_panes
function can be used to divide a worksheet into horizontal or vertical regions known as panes.
This function is different from the Worksheet::freeze_panes
function in that the splits between the panes will be visible
to the user and each pane will have its own scroll bars.
The parameters vertical and horizontal are used to specify the vertical and horizontal position of the split. The units for vertical and horizontal are the same as those used by Excel to specify row height and column width. However, the vertical and horizontal units are different from each other. Therefore you must specify the vertical and horizontal parameters in terms of the row heights and column widths that you have set or the default values which are 15 for a row and 8.43 for a column.
sourcepub fn set_selection(
&mut self,
first_row: WorksheetRow,
first_col: WorksheetCol,
last_row: WorksheetRow,
last_col: WorksheetCol
)
pub fn set_selection( &mut self, first_row: WorksheetRow, first_col: WorksheetCol, last_row: WorksheetRow, last_col: WorksheetCol )
The Worksheet::set_selection
function can be used to specify which cell or range of cells is selected in a worksheet:
The most common requirement is to select a single cell, in which case the first_ and last_ parameters should be the same.
The active cell within a selected range is determined by the order in which first_
and last_
are specified.