This plugin let's you manage an excel file in your application. Bring the power and capability of Microsoft's Excel into your DroidScript application. You can use it pretty much like a database for any informations that you want to display in a table. This library can be use from small to medium file.
Please note that this plugin is not affiliated with Microsoft.To use excel, you must first load the plugin at the top of your script using the LoadPlugin method like this:
Then you can create an instance of excel like this:
props = [ { 'Complete Name': 'name', 'Date of Birth': 'birth', 'Current Address': 'address', 'Age': 'age' } ]
var props = [ { 'Last Name': 'lastName', 'First Name': 'firstName', 'Age': 'age' }, { 'Complete Name': 'comName', 'Current Address': 'currAddress', 'Favorite Color': 'favColor' } ]
Try the following example.
app.LoadPlugin('Excel') function OnStart() { var props = [ { 'Name of Students': 'name', 'Age': 'age', 'Mobile Number': 'number' } ] xls = app.CreateExcel( "myFile.xlsx", props ) xls.SetOnLoad( OnLoad ) xls.Load() } function OnLoad() { var rows = [ { name: "John Doe", age: 26, number: 123456789 }, { name: "Jane Doe", age: 27, number: 123456789 }, { name: "Jhonny Doe", age: 28, number: 123456789 } ] sheet1 = xls.AddSheet( "Sheet1" ) sheet1.AddRows( rows ) xls.Save() }
app.LoadPlugin('Excel') function OnStart() { var props = [ { 'Name of Students': 'name', 'Age': 'age', 'Mobile Number': 'number' } ] xls = app.CreateExcel( "myFile.xlsx", props ) xls.SetOnLoad( OnLoad ) xls.Load() } function OnLoad() { sheet1 = xls.GetSheet( "Sheet1" ) rows = sheet1.GetRows() app.Alert( JSON.stringify( rows ) ) }
app.LoadPlugin('Excel') function OnStart() { // We assume 2 sheets with names "UserA" and "UserB" /* UserA Last Name | First Name | Age UserB Complete Name | Current Address | Favorite Color */ var props = [ { 'Last Name': 'lastName', 'First Name': 'firstName', 'Age': 'age' }, { 'Complete Name': 'comName', 'Current Address': 'currAddress', 'Favorite Color': 'favColor' } ] xls = app.CreateExcel( "myFile.xlsx", props ) xls.SetOnLoad( OnLoad ) xls.Load() } function OnLoad() { userA = xls.GetSheet( "UserA" ) userB = xls.GetSheet( "UserB" ) userA.AddRows([ { lastName: "Stark", firstName: "Sansa", age: 18 }, { lastName: "Stark", firstName: "Rob", age: 25 }, { lastName: "Stark", firstName: "Brandon", age: 12 } ]) userB.AddRows([ { comName: "Arya Stark", currAddress: "Winterfell", favColor: "Black" } ]) xls.Save() }
Adds a sheet into the excel file object.
sheetName: String. The name of the new sheet to be added.app.LoadPlugin( 'Excel' ) function OnStart() { var props = [ { 'Name of Students': 'name', 'Mobile Number': 'number', 'Age': 'age' } ] xls = app.CreateExcel( '/Internal/Documents/myFile.xlsx', props ) xls.SetOnLoad( OnLoad ) xls.SetOnSave( OnSave ) xls.Load() } function OnLoad() { sheet = xls.AddSheet( "Students" ) xls.Save() } function OnSave() { app.ShowPopup( "Excel file is saved successfully." ) }
app.LoadPlugin( 'Excel' ) function OnStart() { var props = [ { 'Name of Students': 'name', 'Mobile Number': 'number', 'Age': 'age' } ] xls = app.CreateExcel( '/Internal/Documents/myFile.xlsx', props ) xls.SetOnLoad( OnLoad ) xls.Load() } function OnLoad() { var prop = { "Title of the Movie": 'title', "Time Duration": 'dur', "Leading Character": 'lead' } sheet = xls.AddSheet( "Movies", prop ) xls.Save() }
Returns the relative path or absolute path to the file.
Returns the sheet object by passing the sheet name.
sheetName: String|Number. The name or the number of the sheet.Load the excel file.
Save the excel file. You should call this method before closing your app to avoid loss of data.
Sets a font-family to the excel document.
fontName: String. The name of the font. You can Arial, Calibri, Times New Roman, and more...Sets the headers style of the excel document.
backgroundColor: String. RGB Hex color "#rrggbb"Calls a function on load.
callback: Function. The function to be called when the file is loaded.app.LoadPlugin( 'Excel' ) function OnStart() { var props = { 'Name of Students': 'name', 'Mobile Number': 'number', 'Age': 'age' } xls = app.CreateExcel( '/Internal/Documents/myFile.xlsx', props ) xls.SetOnLoad( OnLoad ) xls.Load() } function OnLoad() { app.ShowPopup( "Excel object is loaded and ready." ) // do your excel stuff here }
Calls a function on save.
Sets the orientation of the excel document.
orient: String. Values can be 'portrait' or 'landscape'. Default is 'portrait'.Makes the position of the column fixed on the left.
count: Number. The number of columns from the left.Makes the position of the row fixed on the top.
count: Number. The number of columns from the top.Adds a row to a given sheet.
rows: Array. An array of row objects.Multiple rows
rows = [ { name: "John Doe", age: 26, number: 123456789 }, { name: "Jane Doe", age: 27, number: 543216789 }, { name: "Jonn Doe", age: 28, number: 987654321 } ] sheet1.AddRows( rows )
Single row
row = { name: "John Doe", age: 26, number: 123456789 } sheet1.AddRows( row )
Adds a format or styles for the header of certain column.
header: Object. The new header style object of the given prop.sheet1 = xls.GetSheet( "Sheet1" ) var format = { col: "Name of Students", prop: "name" // required } sheet1.FormatHeader( format )
Returns the data of the sheet.
sheet1 = xls.GetSheet( "Sheet1" ) rows = sheet1.GetRows() app.Alert( JSON.stringify( rows ) )
Returns all rows that ends at a specified index.
endRow: Number. The index of the ending row. Starts from zero excluding the header row.Returns all rows that starts at a specified index.
startRow: Number. The index of the starting row. Starts from zero excluding the header row.Returns all rows that pass a certain condition.
prop: String. The prop to be checked.Returns the name of the sheet.
Removes a row in the sheet.
row: Number. The index of the row. Starts from zero excluding the header row.Sets the width of a given prop or column.
prop: String. The prop name or column name.Sets a formula to the given column or prop.
prop: String. The prop name or column name.Formula will apply only after calling xls.Save()
Sets a header object to the sheet.
headers: Array. An array of header objects.sheet1 = xls.GetSheet( "Sheet1" ) var headers = [ "Complete Name:comName", "Current Address:curAddr", "Mobile Number:num" ] sheet1.SetHeaders( headers )
sheet1 = xls.GetSheet( "Sheet1" ) var headers = [ { col: "Complete Name", prop: "comName" }, { col: "Current Address", prop: "curAddr" }, { col: "Mobile Number", prop: "num" } ] sheet1.SetHeaders( headers )
{ col: String, prop: String, align: String. "Left" or "Center" or "Right", alignVertical: String. "Top" or "Center" or "Bottom", height: Number, span: Number, rowSpan: Number, wrap: Boolean, fontWeight: String. "Bold", fontStyle: String. "Italic", color: RGB Hex String, backgroundColor: String, borderColor: RGB Hex String, borderStyle: String. "Thick" }
Sets a new data to the given row.
row: Number. The index of the row. Starts from zero excluding the header row.sheet = xls.GetSheet( "Sheet1" ) newData = { name: "New John Doe", age: 25, number: 79000123791 } sheet.SetRow( 1, newData )
This plugin uses the following libraries: