Book not found

From Documentation
⧼coll-notfound_msg⧽

Return to Documentation.


Spreadsheet Data Model




Spreadsheet Book Model

When Spreadsheet loads an Excel file, the file is converted to Spreadsheet's data model (book model) stored in memory. The root of the data model is a book (Book) and it contains one or more sheets (Sheet) which may contain many cells (CellData), styles (CellStyle, Color), fonts (Font), chart (Chart), and pictures (Picture).

You can directly access model object like Book or Sheet. However, if you want to modify data on cells (or rows and columns), you should use Range interface then Spreadsheet will handle subsequent synchronization stuff for you, e.g. notify other referenced cells.


brief introduce some commonly-used API

Load An Excel File

setSrc()

Spreadsheet also provides API to load an Excel file. ZK Spreadsheet component's Spreadsheet.setSrc(String) can be called to display an Excel file programmatically. Similar to src attribute, this method accepts relative file path.

public class MyComposer extends SelectorComposer<Component> {

	@Wire("spreadsheet")
	Spreadsheet spreadsheet;
	
	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		//initialize stuff here
		spreadsheet.setSrc("/WEB-INF/books/startzss.xlsx");

	}
}
  • Line 3: ZK_Developer%27s_Reference/MVC/Controller/Wire_Components


setBook()

In case you want to display user uploaded Excel book file or display the same Excel book file shared by multiple users, importer interface along with ZK Spreadsheet Spreadsheet.setBook(Book) can be used. Normally one would obtain Book instance by importing an Excel book file. Use Importer.imports(InputStream, String) to import Excel book file. It returns Book instance which can be passed to setBook(Book) to display imported Excel book file.


public class MyComposer extends SelectorComposer<Component> {

	@Wire("spreadsheet")
	Spreadsheet spreadsheet;
	
	@Listen("onUpload = button")
	public void showBook(UploadEvent event) throws IOException{
		Media media = event.getMedia();
		if (media.isBinary()) {
			Importer importer = Importers.getImporter();
			InputStream inputStream = WebApps.getCurrent().getResourceAsStream("/WEB-INF/books/startzss.xlsx");
			Book book = importer.imports(inputStream, "startzss");
			spreadsheet.setBook(book);
		}
	}
}


This is especially powerful in multi-user collaborative scenario. For example once Excel book file is imported using Importer interface and put into application scope, it can be applied to multiple ZK Spreadsheet components each used by different user. ZK Spreadsheet will propagate any changes made to this Book instance to whichever ZK Spreadsheet component it is applied to and therefore facilitate multiple users to collaborate the same Excel book file.


  • setSelectedSheet(String)
  • getBook()

Spreadsheet


change sheet example