r/OfficeScripts • • Sep 07 '21

Excel Office Script - Send data as image

Hi,
I have a script that converts a table into an image for Power Automate to email. The script works but it takes an image of the full table (column A,B &C) when i really only need A2:B last row.

One other problem I have is that it doesn't seem to wrap the text in the image like it does on the excel sheet.

Is there someone out there who might be able to help me with these issues?

function main(workbook: ExcelScript.Workbook): ReportImages {

  // Set sheet visibility to ExcelScript.SheetVisibility.visible
  let dataSheet = workbook.getWorksheet("DataSheet");
    dataSheet.setVisibility(ExcelScript.SheetVisibility.visible);

  // Apply values filter on dataSheet
  let table1 = workbook.getTable("Table1");
    table1.getColumnByName("Column3").getFilter().applyValuesFilter(["1"]);

   // Get the data from the table.
  let sheet8 = workbook.getWorksheet("Sheet8");
  const table = workbook.getWorksheet('DataSheet').getTables()[0];
  const rows = table.getRange().getTexts();

  // Create image
  const tableImage = table.getRange().getImage();
  return { tableImage };
}

// The interface for table
interface ReportImages {
  tableImage: string
}
1 Upvotes

2 comments sorted by

View all comments

Show parent comment

1

u/DevGrr Jan 02 '23

Yes, something like this. Table.getRange() gives you the entire table (with headers, etc, and all columns). You can use Table.getRangeBetweenHeaderAndTotal to remove the header too, and then keep going from there.