as3xls > Number of sheets always 0 - actionscript-3

I'm trying to parse a .xlsx file exported from a google docs. Right now I'm not trying to access it online, I'm manually downloading it and copying inside my application.
I've read the tutorial provided online, and this is the code I have right now:
var contentBA:ByteArray = new ByteArray ();
var fileToLoad:File = File.applicationDirectory.resolvePath("textLabels.xlsx");
var stream:FileStream = new FileStream();
stream.open(fileToLoad, FileMode.READ);
stream.readBytes (contentBA, 0, contentBA.length);
var xls:ExcelFile = new ExcelFile();
xls.loadFromByteArray(contentBA);
trace ("N SHEETS ", xls.sheets.length);
but the number of sheets it's always 0. I tried to change the file and to load the most simple excel ever but it keeps saying 0.
Is it a problem of the ".xlsx" extension? Am I missing something?

AS3XLS was written for the old file format BIFF Office 97 style documents. I've written an XLSX exporter for my work on the AdvancedDataGrid but it's proprietary work so I can't share the code unfortunately. However I can give you some direction. The BIFF format used special codes for encoding things like formatting for cells or formulas, the binary format was seemingly meant to reduce the file size (and perhaps as a form of obfuscation). XLSX instead takes the more open XML approach, creating a BIFF file was complicated and was reverse engineered by the Open Office team before Microsoft ever published the spec for it, the newer XML formats are pretty well documented. Every new office file that ends with the x in it's extension is an archive (just like a zip file, you can open it with any archive tool) with a bunch of XML files inside that define the sheet. I basically took a sample sheet with nothing in it (opened Excel saved a new workbook) then pieced it apart and wrote AS3 classes that corresponded to each of the XML files and each implemented an interface that said it had to have a method to getXMLString() then I wrote a wrapper that would create all the objects and used the container pattern/traversal to build all the XML files needed and used the nochump AS3 zip library to package it together.
A useful tool for inspecting the xlsx or docx or whateverx files can be found here:
http://www.microsoft.com/en-us/download/details.aspx?id=5124
If you're on Mac discussion on one here:
http://openxmldeveloper.org/discussions/development_tools/f/27/p/1494/7453.aspx
Generally the site above was helpful
http://openxmldeveloper.org/
Documentation showing (minimal) examples
http://www.ecma-international.org/news/TC45_current_work/Office%20Open%20XML%20Part%203%20-%20Primer.pdf
NoChump's AS3 Zip library
http://nochump.com/blog/archives/15
Basically for more advanced features like tables or cell spanning I just attempted the change I wanted to be able to make programmatically in a simple Excel file then compared it against another without that new feature using the first tool linked above and implemented the change in the appropriate AS3 class (the one that corresponds to the XML file that changed).
It took about 2 weeks to get the organization of the classes solid but it's absolutely achievable.

ExcelFile is a class from a custom library and it says that supports Excel 2002-2003. What version of Excel do you use?

Related

Can Google Apps Script blobs be returned with their content type set to Spreadsheet?

As part of a suite of tools I am developing for the company I work for, I have an add-on in development that when first installed generates all the relevant files and folders for the suite.
Due to the complexity of some of the files I discovered that using the following code was the quickest way to generate the files:
function createTemplate(branchId){
var home=DriveApp.getFolderById(branchId)
var master=DriveApp.getFileById(stringId).getBlob();
home.createFile(master);
}
I am presented with the problem, however, that all the files generate as PDFs. I am aware that this is because the default blob content type is the PDF file type and that getAs(contentType) can be used to specify the desired blob content type; but I have struggled to find any documentation specifying how to call the content type as a Spreadsheet, for example.
Is this possible and I've just missed somewhere in Google's documentation how to specify content type as spreadsheet or is it no possible and can blobs only be returned with content types of PDF or image types?
UPDATE: So I discovered accidentally that the content type for spreadsheets would appear to have be specified by application/vnd.google-apps.spreadsheet However, I now get the error Converting from application/pdf to application/vnd.google-apps.spreadsheet is not supported.
FURTHER UPDATE: Potential solution using different route found using the below script:
function createTemplate(branchId){
var home=DriveApp.getFolderById(branchId);
var master=DriveApp.getFileById("fileId").makeCopy("PP Template", home);
}
Although this had around an 8 second run-time so not the quickest thing in the world. Blob related answer still welcome.
As far as I am aware, blob will not do what you want to at this time. There is a reason that DocumentApp.create, etc. exist. They are the function calls that Google wants you to make for what you want to do. They don't want 13 ways to perform the same function.

Creating a CSV file with the Report Generation Toolkit in Labview

I want to create .csv files with the Report Generation Toolkit in Labview.
They must actually be .csv files which can be opened with Notepad or something similar.
Creating a .csv is not that hard, it's just a matter of adding the extension to the file name that's going to be created.
If I create a .csv file this way it opens nicely in excel just the way it should, but if I open it in Notepad it shows all kind of characters and it doesn't even come close to the data I wrote to the file.
I create the files with the Labview code below:
Link to image (can't post image yet because I've got to few points)
I know .csv files can be created with the Write to Spreadsheet VI but I would like to use the Report Generation Toolkit because it's pretty easy to add columns and rows to the file and that is something I really need.
you can use the Robust CSV package on the lavag.org forum to read and write 2D arrays to CSV files.
http://lavag.org/files/file/239-robust-csv/
Calling a file "csv" does not make it a CSV file. I never used the toolkit to generate an Excel file, but I'm assuming it creates an XLS or XLSX file, regardless of what extension you give it, which is why you're seeing gibberish (probably XLS, since it's been around for a while and I believe XLSX is XML, not binary).
I'm not sure what your problem is with the write spreadsheet VI. It has an append input, so I assume you can use that to at least add rows directly to a file, although I can't say I ever tried it. I would prefer handling all the data in memory explicitly, where you can easily use the array functions to add rows or columns to the array and then overwrite the entire file.

Working with Excel Files in AS3

I'm trying to save some data to an Excel file from Adobe AIR. I'm using the as3xls library hosted on Google Code, but it doesn't seem to SAVE formulas. For example, if I set the value of a cell to =SUM(B1:B38), it evaluates it as a string when I open the saved document. I was curious if any export here has any sort of knowledge on how to build in formulas into an Excel document. I'm not too saavy on the XLS or XLSX data format.
I am familiar with many other programming languages, so if someone knows of a really great library for doing this sort of thing, let me know!
I have been not try it, but Try it:
as3xls.swc

Saving several images (and metadata for each) in a single file using Adobe Air

Is it possible, via Adobe Air, to save multiple types of data in a single file? For example, an application would allow the user to load in external images, position them on stage and label them. This data would be then be stored in a ByteArray (I guess) using BitmapData for the images and probably XML for the metadata.
I would then like to write this to a single file, with a bespoke file extension that could be associated with said Air app.
I've asked this on various forums and never received a single reply.
You can add everything to a byte array and write it to file - but defining boundaries and extracting individual entities back from the file would take some effort. How about writing them to normal files, zipping them to a single file and deleting the originals? This way you can still have a single file and deal with the individual items more easily.
This article describes some ActionScript zip libraries. I've used nochump in the past and it was easy - this page has some sample code
If you want some individuality for your files, you can rename the zipped file to whatever extension you want - that's what Firefox extensions do, they have .xpi extension, but they're plain zip files renamed.

(OpenXML) Add data pages to xml package without framework

lately I've been into combining multiple OpenXML speadsheets via PHPExcel which
showed me that this framework has certain issues which makes it pretty much unusable
for what I want to do (my related SO question).
To make it short: it's hard to guarantee that all formatting features of Excel 2007 will
persist a file merge performed with that particular framework.
Anways, now I'm thinking of a more general approach. I want to open a template XLSX
which contains various formatting and add some plain alphanumeric data worksheets 'at the end' of the workbook.
Is sensefully possible to do the following:
unzip template XLSX
parse XML files
add worksheets
save xml files
rezip files to get valuid XLSX
Any hints or experiences would be highly appreciated.
thanks in advance
K
I haven't worked with .xlsx too much, but I've altered .docx files by manually adding and editing the XML.
The biggest concern with adding new parts to a document is to make sure you update the .rels files. The best way to figure out what needs to be updated is to create a new .xlsx document in Excel, add a worksheet, save the file and then unzip it to see what has changed. You can also use the DocumentReflector tool that comes with the OpenXML SDK if you want to see the internals of the file without having to unzip it.
I found the OpenXML reference manual very helpful when hand editing files because it tells you what elements you have to keep and what elements are optional to make a valid document. It makes it easier to work with when you can remove some of the extraneous elements that Excel adds automatically.