Sub Process_Globals
End Sub
Sub Globals
Dim table1 As Table
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.Title = "Excel Example - Lyndon Bermoy"
Activity.AddMenuItem("Load Table", "LoadTable")
Activity.AddMenuItem("Save Table", "SaveTable")
LoadTable(File.DirAssets, "Book1.xls")
End Sub
Sub LoadTable_Click
If File.Exists(File.DirRootExternal, "book1.xls") = False Then
ToastMessageShow("Unable to open file.", True)
Else
LoadTable(File.DirRootExternal, "book1.xls")
End If
End Sub
Sub LoadTable(Dir As String, FileName As String)
Dim workbook1 As ReadableWorkbook
Dim moviesSheet As ReadableSheet
workbook1.Initialize(Dir, FileName)
moviesSheet = workbook1.GetSheet(0)
If table1.IsInitialized Then
Activity.RemoveAllViews 'remove the current table
End If
table1.Initialize(Me, "Table1", moviesSheet.ColumnsCount)
table1.AddToActivity(Activity, 0, 0, 100%x, 100%y)
For row = 0 To moviesSheet.RowsCount - 1
Dim values(moviesSheet.ColumnsCount) As String
For i = 0 To values.Length -1
values(i) = moviesSheet.GetCellValue(i, row)
Next
If row = 0 Then
table1.SetHeader(values)
Else
table1.AddRow(values)
End If
Next
End Sub
Sub SaveTable_Click
'first we create a writable workbook.
'the target File should be a NEW File.
Dim newWorkbook As WritableWorkbook
newWorkbook.Initialize(File.DirRootExternal, "1.xls")
Dim sheet1 As WritableSheet
sheet1 = newWorkbook.AddSheet("Movies", 0)
'add the headers To the sheet
'we create a special format For the headers
Dim cellFormat As WritableCellFormat
cellFormat.Initialize2(cellFormat.FONT_ARIAL, 12, True, False, False, _
cellFormat.COLOR_GREEN)
cellFormat.HorizontalAlignment = cellFormat.HALIGN_CENTRE
cellFormat.SetBorder(cellFormat.BORDER_ALL, _
cellFormat.BORDER_STYLE_MEDIUM, cellFormat.COLOR_BLACK)
cellFormat.SetBorder(cellFormat.BORDER_BOTTOM, cellFormat.BORDER_STYLE_THICK, _
cellFormat.COLOR_BLUE)
cellFormat.VertivalAlignment = cellFormat.VALIGN_CENTRE
cellFormat.BackgroundColor = cellFormat.COLOR_GREY_25_PERCENT
Dim col As Int = 0
For Each lbl As Label In table1.Header
Dim cell As WritableCell
cell.InitializeText(col, 0, lbl.Text)
cell.SetCellFormat(cellFormat)
sheet1.AddCell(cell)
sheet1.SetColumnWidth(col, 15)
col = col + 1
Next
sheet1.SetColumnWidth(1, 40)
sheet1.SetRowHeight(0, 15)
'add the data
Dim rowsFormat As WritableCellFormat
rowsFormat.Initialize
rowsFormat.HorizontalAlignment = rowsFormat.HALIGN_CENTRE
For col = 0 To table1.NumberOfColumns - 1
For row = 0 To table1.Size - 1
Dim cell As WritableCell
cell.InitializeText(col, row + 1, table1.GetValue(col, row))
cell.SetCellFormat(rowsFormat)
sheet1.AddCell(cell)
Next
Next
'Must call write AND close To save the data.
newWorkbook.Write
newWorkbook.Close
End Sub
Sub Table1_CellClick(Col As Int, Row As Int)
table1.SetValue(Col, Row, "xxx")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub