old_array_formula/
old_array_formula.rs

1use edit_xlsx::{Workbook, WorkbookResult, Write};
2
3fn main() -> WorkbookResult<()> {
4    /// In Office 365, many new functions have emerged.
5    /// However, these functions may conflict with older versions of Excel.
6    /// You can use the 'write_old_formula' method,
7    /// which will minimize potential conflicts as much as possible.
8
9    // Create a new workbook
10    let mut workbook = Workbook::new();
11    // Use the default worksheet
12    let worksheet = workbook.get_worksheet_mut(1)?;
13    // Write some test data.
14    worksheet.write("B1", 500)?;
15    worksheet.write("B2", 10)?;
16    worksheet.write("B5", 1)?;
17    worksheet.write("B6", 2)?;
18    worksheet.write("B7", 3)?;
19    worksheet.write("C1", 300)?;
20    worksheet.write("C2", 15)?;
21    worksheet.write("C5", 20234)?;
22    worksheet.write("C6", 21003)?;
23    worksheet.write("C7", 10000)?;
24    // Write an array formula that returns a single value
25    worksheet.write_old_formula("A1", "_xlfn.SUM(B1:C1*B2:C2)")?;
26    // Same as above but more verbose.
27    worksheet.write_old_formula("A2", "_xlfn.SUM(B1:C1*B2:C2)")?;
28    // Write an array formula that returns a range of values
29    worksheet.write_old_formula("A5", "_xlfn.TREND(C5:C7,B5:B7)")?;
30
31    workbook.save_as("examples/old_array_formula.xlsx")?;
32    Ok(())
33}