ASP.NET generated excel file has different format than extension - asp.net

I have a web application made in old asp.net 2.0. I need to generate excel file with specific formated table (the best way if I can load the template and only put data in code behind). To do this I'm trying to use this library CarlosAg.ExcelXmlWriter:
http://www.carlosag.net/tools/excelxmlwriter/sample
And the final file is generated very well, but when I'm trying to open it in MS Excel warning popup appear with information that file has different format than the extension (xls). And also question if I want to open it if I trust the source of file. When I click yes, the file opened properly. On the other pc with different version of Excel, there's also warning, but different - file is broken and cannot be opened, the same in mobile (no possibility to open). What is interesting - I can open that file properly without any warnings in different office program, ex. WPS Office.
So I make two steps back and try to open just simple file generated by the sample of Carlos library and effect is the same. Is there any chance to "fix" the file in code behind so MS Excel could also open it properly without any warnings?
Dim book As Workbook = New Workbook()
Dim sheet As Worksheet = book.Worksheets.Add("Sample")
Dim row As WorksheetRow = sheet.Table.Rows.Add()
row.Cells.Add("Hello World")
book.Save("D:\Folder\test.xls")

You have to give the file extension xlsx.
The older xls is in fact the legacy (closed) binary format of office files.
However, since office 2007, Microsoft has adopted a open xml format for ALL office documents (well, ok, outlook pst, and MS-Access are exceptions). In fact, if you take any office document (word, power-point, excel) etc., try renaming the xlsx document as a zip file. You find that you can now open the zip archive, and you can see/look at and even modify the xml in that document.
(do try this rename as a zip file for fun and giggles - you see how you actually don't even need any 3rd party tools to open, play with, and mess with the content in the zip archive (so, all office documents are in fact a simple zip archive!!!).
So, newer office file formats are in fact xml markup - and you can modify it!!
Anyway, without a doubt that library you are using thus uses the above feature/fact of office documents now being xml formatted and NOT a propriety Microsoft binary format - you can in fact modify such documents now on ANY computer that is able to open a zip file, and modify text files.
As a result, you are giving the document name a legacy binary file name (xls), but opening a xml formatted file (plain text), and thus Excel is detecting this fact/issue. So, you need to give that document the open office xml format extension (xlsx).

Related

Sharing a paw file in plain text

In Paw, it was possible to easily share a paw file in a repository as part of the documentation because it was stored in plain text, making changes to it legible.
Artsy is doing it in its energy project and they wrote some blog posts about this.
However, since the 3.x release, it appears that the file is now stored in binary format.
Am I missing a hidden option to save in xml format or is the feature completely gone?

Generate Word (docx) Files with from Templates (dotx) on Server Application

I'm currently working on a project where I have to transfer an existing VB program into a Server Application using ASP.NET.
While I had success doing that there's one thing that I'm struggeling with:
The VB Program was using Microsoft Word Interop to generate Excel files and fill Word Templates with data. While i managed to be able to generate the files locally with Interop I can't get it to work for somebody that is accessing the Application from a client.
I also tried using OpenXML to solve my problem but somehow it always said that the file is corrupt after I tried to fill the bookmarks.
In the end the user shoud be able to download the Word document filled with the necessary data.
What would be the best solution for this problem?
If you have mostly the same document structure, you can prepare the whole document in Word. Set placeholders in the document like {Placeholder1} {Placeholder2}, parse the XML and Replace the Placeholders with your text, so you must not generate the whole document structure. Only Replace the Placeholders with your text.

Convert RTF to PDF on a rule into Alfresco

I found a link (http://wiki.alfresco.com/wiki/Content_Transformations) that says that i need to create a file named my-transformers-context.xml and put my configurations there to convert RTF to PDF...
There says that some configuration are already configured but this one (RTF to PDF) and some others (DOC to PDF) are not.
By the way i couldn't find how to create this xml with the right configuration to convert the RTF file into a PDF...
Someone already done something like this? or someone know a link that explain how to configure this xml file?
PROBLEM SOLVED!!!!
I don't know if there is a way to say that i've solved the problem... But here it goes the solution...
I saw what Gagravarr said and started looking for configuration of openoffice into alfresco...
There is a file named:
alfresco-global.properties
and there is two variables named:
ooo.exe
and
ooo.enabled
the first one must indicate the path to sopenoffice.exe
and the second one must be equal to true...
ooo.enabled = true
That solve a lot of problema to convert some kind of file to another... like RTF to PDF...
Out of the box, Alfresco should be able to transform a RTF file to a PDF using OpenOffice (direct or JodConverter, depending on if you're on Community or Enterprise)
Assuming you're on a new enough Alfresco, this webscript will tell you what transformations are available from and to RTF:
http://localhost:8080/alfresco/service/mimetypes?mimetype=application/rtf#application/rtf
If that doesn't show you RTF -> PDF, then you need to look at your open office configuration/setup

Automatically adding rows to excel file template

I am running .net 4.0 asp.net app on IIS 7. I want to know if there is an easy way of adding rows to an excel 2007/2010 (not too fussed) template file that a user can download from the server.
For example, the user might check a couple of tick boxes and clicks a button on the web page. The server does a sql query on a table and comes back with the results. I have an excel file with some headings, column titles, formatting etc. on the web app's resources directory. I want to make a copy of this file, insert each of the results as a row into this file (insert first name into cell A3, last name into cell B3 etc.). And make it available for the user to save on their disk.
Since Excel (xls) format is an "Open format", I was wondering how easy/straight forward this would be. Is it a matter of loading the excel XML DOM and inserting XML elements? What are libraries I need to use?
Any help or resources would be greatly appreciated.
I did exactly this using an Excel template. You'll see how easy it is to do this using open source libraries as NPOI.
These links should help you get there:
Create Excel (.XLS and .XLSX) file from C#
Creating Excel spreadsheets .XLS and .XLSX in C#

asp.net - Generate Powerpoint file on the fly

I have a client of my web based application who heavily uses the data from our system for powerpoint presentations.
We currently allow data to export in more traditional file types...PDF, CSV, HTML, and a few others. Powerpoint doesn't seem to be really automated.
Is there a way, on the ASP.NET server side, to automate the creation and on-demand download of a powerpoint file format for a report from a system?
There's some documentation on MSDN about the OpenXML format that they're using:
Manipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Format API (Part 1 of 2)
Manipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Format API (Part 2 of 2)
In this article, Steve suggests using Aspose's Slide application.
He also explains step by step on how to generate the PowerPoint file.
Here are some code excerpts (in VB):
Opening an existing PowerPoint file:
Dim fs As System.IO.FileStream = _
New System.IO.FileStream("c:\mypath\myfile.ppt", _
System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim MyPres As Presentation = New Presentation(fs)
fs.Close()
Looping the slides and outputting their template formats:
Dim slides As Slides = MyPres.Slides
For i As Integer = 0 To slides.Count - 1
Response.Write(MyPres.Slides(i).Layout.ToString + "<br>")
Next
In his article, he describes more in detail on how to do it.
Well you have two ways of really doing this, without third party tools. The first would be with Automation of PowerPoint, but that requires that your server have PowerPoint installed. The second is to utilize the new pptx file file format and generate the powerpoint document using XML.
I have found that the best way to get started on the XML side is to simply create a powerpoint that does what you want, then save it and look at the XML. You can also review the microsoft documentation. Overall working with the XML formats is pretty easy.
Lastly, there might be some third party items out there, but be careful that they don't require COM automation.
In regards to the previous poster, your statement is incorrect.
You really only have one option for server side ASP.NET automation of this process.
Use the open xml links mentioned by Ben in the original answer...
Manipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Format API (Part 1 of 2)
Manipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Format API (Part 2 of 2)
The reason for this is that server side automation of office is completely unsupported and is bad coding practise, running com automation servers that are designed for interactive usage in a non-interactive environment is a potential recipe for disaster.
so in summary use the open xml api and generate your pptx's.
There are also other third-party options similar to Aspose Slides, such as OfficeWriter's PowerPoint Writer.
I'm not exactly sure how Aspose Slides works, but with PowerPoint Writer you have an existing, formatted PowerPoint presentation with data markers in it, the you process it with PowerPoint Writer to replace the data markers with data. Here are some examples.
there is another method ,convert your power point presentation to images or xps(silver light presentation) and then use some sort of json(jquery) to show and download them.
i implement the images and xps silver light presentation in my web application

Resources