3.3 Serialization interface

If you don't want to use xlsx.hwp's library interface (see above) for some reason, you can also use the plugin's serialization interface. This is easier to use because it only requires a single function call to convert Hollywood tables to XLSX documents and vice versa but you won't have fine-tuned control over everything as you have when using the library interface.

Access to the xlsx.hwp's serialization interface is through Hollywood's SerializeTable() and DeserializeTable() functions, or, alternatively, through the ReadTable() and WriteTable() functions. By using the serialization interface, you can convert an XLSX document into a Hollywood table through just a single function call:

 
t = DeserializeTable(FileToString("test.xlsx"), "xlsx")

The code above will read all rows and columns from test.xlsx and store them in the Hollywood table t. You could then print all rows and columns in that table like this:

 
For Local y = 0 To ListItems(t) - 1
   For Local x = 0 To ListItems(t[y]) - 1
      DebugPrint(t[y][x])
   Next
Next

You could then simply change cell values by writing new values to the t table. For example, the following code changes the value of the cell in the 5th column and the 10th row to "Hello":

 
t[9][4] = "Hello"

When you're done with all modifications, you can simply convert your Hollywood table back into an XLSX document in just a single line like this:

 
StringToFile(SerializeTable(t, "xlsx"), "test2.xlsx")

The code above will convert the table t to an XLSX document using the xlsx.hwp plugin and save the XLSX document as test2.xlsx.

As you can see, the serialization interface is very easy to use but doesn't offer as much flexibility as the library interface which gives you fine-tuned control over many XLSX documents features.


Show TOC