[]
This article introduces the interaction features of DsExcel with SJS and SSJSON formats at the workbook and worksheet levels during IO operations with SpreadJS.
DsExcel allows you to render column width based on pixels instead of characters using setPixelBasedColumnWidth method of WorkbookOptions class when exporting a .sjs file or an SSJSON file as a PDF or image.
Refer to the following example code to render column width based on pixels when exporting as a PDF or image:
// Initialize WorkbookOptions.
WorkbookOptions workbookOptions = new WorkbookOptions();
// Enable pixel-based column width for the workbook.
workbookOptions.setPixelBasedColumnWidth(true);
Workbook workbook = new Workbook(workbookOptions);
// Open SSJSON file.
workbook.open("Event budget.sjs");
// Uncomment below code when importing .ssjson file.
//workbook.open("Event budget.ssjson");
IWorksheet worksheet = workbook.getWorksheets().get(0);
// Save to a PDF and PNG file.
workbook.save("SavePDFWithPixelBasedColumnWidth.pdf");
worksheet.toImage("SavePDFWithPixelBasedColumnWidth.png");
DsExcel allows you to set various properties of Tab Strip like its position, width, display new tab button, editing of worksheet name etc. while performing JSON I/O. The IWorkbookView interface provides methods like setTabNavigationVisible, setNewTabVisible, setAllowSheetReorder, setTabStripWidth, setTabStripPosition etc.
Refer to the following example code which sets the position of tab strip to left and other tab strip properties.
//create a new workbook
Workbook workbook = new Workbook();
workbook.getWorksheets().add();
workbook.getBookView().setAllowSheetReorder(false);
workbook.getBookView().setTabEditable(false);
workbook.getBookView().setTabNavigationVisible(false);
workbook.getBookView().setTabStripPosition(SpreadJSTabStripPosition.Left);
workbook.getBookView().setTabStripWidth(150);
workbook.getBookView().setNewTabVisible(false);
try {
workbook.toJson(new FileOutputStream("sheettabposition.json"));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
DsExcel supports retrieving information about SpreadJS worksheet tabs. This includes details such as the number, name, type, and index of TableSheets, GanttSheets, and ReportSheets. You can download a JSON file containing the worksheet tab information from heresheettabs.sjs.
DsExcel provides the getSheetTabs property of the IWorkbook interface, making it easy for you to obtain information about all worksheet tabs.
Refer to the following code to get the number, name, type, and index of all worksheet tabs in the workbook.
// Create a new workbook.
Workbook workbook = new Workbook();
// Open the JSON file.
workbook.open("sheettabs.sjs");
ISheetTabs sheetTabs = workbook.getSheetTabs();
// Get the number of sheet tabs.
System.out.println("The count of sheet tabs: " + sheetTabs.getCount());
// Get the name, type, and index of each worksheet.
for (ISheetTab item : workbook.getSheetTabs()){
System.out.println("Sheet name: " + item.getName()+", Type: "+ item.getSheetType()+", Index: " +item.getIndex());
}