I am getting a blank spreadsheet called "object" on my export - aspose-cells

I am running C#.NET, and Aspose version 7.3.
When I export my sheet, it exports completely fine. No problems. Nuttin but love.
However, when I click 'save as' in the browser options (as opposed to 'open'), and open that resultant file, there is an empty spreadsheet titled "Object."
Please see the screen shot below.
http://imgur.com/yjHy2
Is there any way that I can suppress this? It's not showing in my worksheet collection at run-time. I am also having trouble googling it, as "object" is a pretty common word when it comes to Aspose Cells.NET development.
Your assistance is appreciated. Thanks.

Probably, you might be creating Object worksheet accidentally or may be Object worksheet already exist in your template file.
Anyway, please try the following sample code and see what results you get. It should work fine without any problem.
If it works fine, you can then modify your code according to this code.
For saving in Xls format, please use XlsSaveOptions
and
For saving in Xlsx format, please use OoxmlSaveOptions
Sample Code in C#
//Create a new workbook
Workbook workbook = new Workbook();
//Get the first worksheet in the workbook
Worksheet sheet = workbook.Worksheets[0];
//Rest of your code goes here
string yourFileFormat = "XLS";
//Save file and send to client browser using selected format
if (yourFileFormat == "XLS")
{
workbook.Save(HttpContext.Current.Response, "output.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
}
else
{
workbook.Save(HttpContext.Current.Response, "output.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
}
HttpContext.Current.Response.End();

Related

.getBlob().as('application/pdf') is converting the wrong file even though the file id is correct [duplicate]

I have a Google Docs template which is automatically copied into a folder and replace specific values with values coming from spreadsheet cells.
The template contains values such as <<41>> which are used to be "find-and-replaced" with values coming from a spreadsheet.
The find-and-replace process is fine, and the results of the document looks like this image below
Now, I want this document to be converted into PDF after it has been updated, so I made a function for the convertion and call it at the bottom after all the codes has been executed.
Here's the function:
//convert to PDF
function convertPDF(FileID,newName) {
Utilities.sleep(120000);
docblob = DocumentApp.openById(FileID).getAs('application/pdf');
/* Add the PDF extension */
docblob.setName(newName + ".pdf");
var file = DriveApp.createFile(docblob);
}
The convertion works fine, but the converted document isn't updated. Rather, it is like it was the one freshly copied from the template, before the values were changed.
If you may notice, I have added a "sleep" timer before in the conversion function so as to delay the conversion and give time for the changes to be saved, I've tried 1 and 2 minutes sleep but still it doesn't work.
What can I do to make sure the PDF is created from the updated template?
The function I provided above works fine, we just need to forced the script to save the changes by calling the saveAndClose() method before calling the function that converts the doc into PDF.
I was searching for an answer for this same problem but for Google Sheets. Gave saveAndClose() a shot, but it didn't work for Sheets. Did some more searching and found that the Sheets solution for a similar problem is:
SpreadsheetApp.flush()
Here is the relevant Question/Answer.
Hope this helps someone get to their answer faster.

Script Can't Open Document (Inaccessible, Please Try Again)

I'm trying to create a copy of a document and populate it with data from a spreadsheet. I can successfully create the copy but the script can't seem to access it to edit its contents. Here's the code:
var file = DriveApp.getFileById('1mWFhZpZVJpYJleg9n5qq3tr7EHwUIlbM');
var copy = file.makeCopy('SKPembimbing_' + nim, folder).getId();
var doc = DocumentApp.openById(copy);
var body = doc.getBody();
It always gives me an error at the 3rd line when it tries to open the document for editing.
(Exception: Document is inaccessible. Please try again later.)
I saw another thread from last year with the same exact question but without a solution. I've been working all night trying to get this darn thing to work. Does it have to do with my scope? I'm running it on a trigger on edit.
I found the solution:
The template document I was copying was a .docx file, NOT a Google Doc. The copied file was thus also a .docx file so was inaccessible from the DocumentApp. All I had to do was convert it to a Google Document.

VBA Open several HTML files in Spreadsheets only in the Workbook currently open

I am downloading HTML files using VBA and Python. These files are on a file directory like C:\files. Every download gives me about 7 - 12 HTML files.
What I want is a way to open each HTML file on one workbook the one which i currently work with.
By using the Open function of VBA for every HTML file i get a new workbook which creates congestion and mess.
Is there a way to have a command inside the loop which opens the HTML file on new tab and inside the current workbook?
I can think of two options: move the sheet from the new workbook into the current one each time; or look at using Querytables.
Moving the sheet is straightforward:
Dim wb As Workbook
For Each varFilePath In colFilePaths 'whatever your loop logic is...
Set wb = Workbooks.Open(varFilePath)
wb.Worksheets(1).Copy Before:=ThisWorkbook.Worksheets(1)
wb.Close False
Next varFilePath
The other option, Querytables, is designed to extract data from HTML rather than just create a worksheet that looks close to how the HTML will render in a browser. Generally the results won't look the same as the webpage, but you do get more control. This may or may not be helpful depending on what you are going to do with the data afterwards. See the VBA documentation for QueryTables for more info, but the basic steps are to create a new QueryTable pointing at your file and the destination cell, set options, and then call its Refresh method to populate cells:
'inside your loop...
Set ws = ThisWorkbook.Worksheets.Add
Set qt = ws.QueryTables.Add("URL;file:///" & varFilePath, ws.Range("A1"))
'set various options here...
qt.WebFormatting = xlWebFormattingAll
qt.WebSelectionType = xlEntirePage
'Get the data
qt.Refresh

as3xls > Number of sheets always 0

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?

How to reference an embedded PowerPoint or Excel file in a form in Access?

So if I was to take a an Access form, and embed either an Excel spreadsheet into it or a PowerPoint deck, how would I reference it in VBA code?
I know I have to set the libraries, name the frame of the OLE object, and use applicable syntax to whatever I want to do, with whatever I stick in the form, however the only things I have ever done with Excel and/or PowerPoint is automate the opening of a seperate window/application from Access, not within the Access form. So I am not sure how to proceed.
If I said its a new Excel.Application, then set xls = to (the ss in the file, and not some file path of another Excel file somewhere)?
Does that make sense?
Let's say you added an Excel Workbook Object in your Form, named it xLObject and added a Reference to the Excel Object Library in VBA
Here is how you Access a Sheet of this Object and change a Range
Dim sheet As Excel.Worksheet
Set sheet = xlObject.Object.Sheets(1)
sheet.Range("A1") = "Hello World"
The same logic applies to Powerpoint.