 |
|
 |
Why don't you write directly to file?!
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
It is one of the most terrible code, that I've ever seen.
|
|
|
|
 |
|
 |
Totally Agree,
There are thousand ways to create more efficient Excel-XML code, few of them could be like create a XSD , use A custom Class for writing xml and so on.
you can do better then string concat / string builder.
|
|
|
|
 |
|
 |
This is a great piece of code! I was trying to open the XML Spreadsheet directly without saving the file. But I get the xml content dumped on the excel file generated. It doesn't show me in excel format. Any idea what I am missing? My code is something like this
System.IO.MemoryStream msExcelMS = null;
string strExcelXml = objExport.GenerateWorkSheetWithSB();
byte[] arrExcelByteData = System.Text.Encoding.Unicode.GetBytes(strExcelXml.ToString());
msExcelMS = new System.IO.MemoryStream(arrExcelByteData);
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=" + strExportFilename);
Response.Charset = "";
Response.BinaryWrite(msExcelMS.ToArray());
Response.End();
msExcelMS.Close();
TIA
Shyamal Bhowmik
|
|
|
|
 |
|
 |
Is there a way to genrate an excel using the programme to generate an excel which will be compatible with both excel 2000 and excel 2003. I used an similar mechanism to generate excel...works fine with excel 2003 but when tried to open with excel 2000 it shows junk value.
Any help would be appreciated.
Thanks
|
|
|
|
 |
|
|
 |
|
 |
Hi friends,
I Downloaded this code but i can't understand how the path of style.config taking and then how to insert to color for the merge cells(Any cells). How to access our own data from database and how to save specified data in the particular cell.
Thanks in advance.
|
|
|
|
 |
|
 |
Hi, this article talks about low level storage stuff, so you won't find answers to your questions here.
What you need is some higher level API for manipulating Excel files. There are many solutions: Excel Automation, OleDb, 3rd party libraries.
I recommend you take a look at GemBox.Spreadsheet Excel C# component. Very fast and easy to use!
To prove ease of use, here is a code snippet how to export DataSet to Excel:
var ef = new ExcelFile();
foreach (DataTable dataTable in dataSet.Tables)
{
var ws = ef.Worksheets.Add(dataTable.TableName);
ws.InsertDataTable(dataTable, "A1", true);
}
ef.SaveXls("DataSet.xls");
|
|
|
|
 |
|
 |
hi
i have created an excel sheet using string builder class. i have to display dropdownlist on excel sheet. i am successful in doing so but when i m using this excel sheet to bind a datagrid i m not able to display the dropdownlist values. Pls help me out
-- modified at 1:35 Thursday 11th October, 2007
|
|
|
|
 |
|
 |
honestly binding a excelsheet to datagrid is something new to me also , i have never tried this . If you can give me more details how are you binding data , I can try . All i have tried is to bind a Excel (worksheet - a worksheet works like a table ) to a datagrid . I can set a value of dropdown embedded in a row of datagrid. but the datasource of dropdown needs to be from a different worksheet or table .
I guess it is not possible to have a single datatable as datasource , binding to datagrid and a dropdown embedded in datagrid without manipulating the datatable.
Thanks,
Jyoti Prakash Deka
Dekajp@yahoo.com
|
|
|
|
 |
|
 |
Hi, good job
I run your app, then opened the file, I found a lot of strange carac terrs :
ഀ ഀ ഀ ഀ ഀ ഀ ഀ ഀ ഀ ഀ ഀ ഀ ഀ ഀ ഀ ഀ ഀ ഀ ഀ ഀ
Any idea, thanks
salam
|
|
|
|
 |
|
 |
I forgot to say that it is not opening in Excel also
|
|
|
|
 |
|
 |
Please let me know which version of Excel are you using It is working fine with My Version I am using Microsoft Excel 2003 SP1 Which is part of Microsoft Office 2003
Thanks
Thanks
|
|
|
|
 |
|
 |
I am using Office 2003 on an XP pro box. I will check if I have SP at office and let you know
Thanks
|
|
|
|
 |
|
 |
does anyone know how to get this working for office 2000? I need exporting features to multiple worksheets...
This code just puts all of the information into one cell and only one worksheet.
Thanks,
Carlito
|
|
|
|
 |
|
 |
This code creates multiple worksheets (can go moretahn 500 ) in Excel 2003 . But I suppose it should also work for office 2000 if it is not working then please create an excel sheet ( with 2 worksheet ) and save it as xml and just compare the excel code (xml) same with my code (generated by application) you will find the difference and the same has to be incorported in to your code
Thanks
--
Jyoti
dekajp@yahoo.com.
|
|
|
|
 |
|
 |
excel 2000 does not appear to have a 'save as xml' option...Has anyone had any luck with 2000 and multiple sheets?
Thanks,
|
|
|
|
 |
|
 |
I am also looking for a way to write to multiple sheets using xml which would work with excel 2000. I found the following code online, which does the job creating a second worksheet, however now I am trying to figure out how to actually write to the second sheet: <html xmlns ="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=Content-Type content="text/html; charset=windows-1252"> <meta name=ProgId content=Excel.Sheet> <meta name=Generator content="Microsoft Excel 9"> </head> <body link=blue vlink=purple> <!-- Creation of 2 worksheets - data1 and data2 --> <xml> <x:ExcelWorkbook> <x:ExcelWorksheets> <x:ExcelWorksheet> <x:Name>data1</x:Name> <x:WorksheetOptions> <x:Selected/> <x:ProtectContents>False</x:ProtectContents> <x:ProtectObjects>False</x:ProtectObjects> <x:ProtectScenarios>False</x:ProtectScenarios> </x:WorksheetOptions> </x:ExcelWorksheet> <x:ExcelWorksheet> <x:Name>data2</x:Name> <x:WorksheetOptions> <x:Selected/> <x:ProtectContents>False</x:ProtectContents> <x:ProtectObjects>False</x:ProtectObjects> <x:ProtectScenarios>False</x:ProtectScenarios> </x:WorksheetOptions> </x:ExcelWorksheet> </x:ExcelWorksheets> </x:ExcelWorkbook> </xml> <table x:str border=0 cellpadding=0 cellspacing=0 width=128 style='border-collapse: collapse;table-layout:fixed;width:96pt'> <col width=64 span=2 style='width:48pt'> <tr height=17 style='height:12.75pt'> <td height=17 width=64 style='height:12.75pt;width:48pt'>S1_R1_C1</td> <td width=64 style='width:48pt'>S1_R1_C2</td> <td width=64 style='width:48pt'>S1_R1_C3</td> </tr> <tr height=17 style='height:12.75pt'> <td height=17 width=64 style='height:12.75pt;width:48pt'>S1_R2_C1</td> <td width=64 style='width:48pt'>S1_R2_C2</td> <td width=64 style='width:48pt'>S1_R2_C3</td> </tr> </table> <xml> <x:ExcelWorkbook> <x:ActiveSheet>1</x:ActiveSheet> </x:ExcelWorkbook> </xml> <!-- This should fillup the second worksheet but it is till write into the 1st one --> <!-- S2_R1_C1 S2_R1_C2 S2_R1_C3 --> <table x:str border=0 cellpadding=0 cellspacing=0 width=128 style='border-collapse: collapse;table-layout:fixed;width:96pt'> <col width=64 span=2 style='width:48pt'> <tr height=17 style='height:12.75pt'> <td height=17 width=64 style='height:12.75pt;width:48pt'>S2_R1_C1</td> <td width=64 style='width:48pt'>S2_R1_C2</td> <td width=64 style='width:48pt'>S2_R1_C3</td> </tr> <tr height=17 style='height:12.75pt'> <td height=17 style='height:12.75pt'>Row2</td> <td>Col2</td> </tr> </table>
</body> </html>
|
|
|
|
 |
|
 |
Actually, it appears that if you have multiple worksheets, then you have to use the <x:WorksheetSource> tag to specify the corresponding worksheet HTML file. This is an excerpt from the MS Office HTML and XML Reference: "When a workbook contains a single worksheet, the Name, WorksheetOptions, and WorksheetSource subelements are required and stored in the workbook HTML file. When a workbook contains multiple worksheets, only the Name and WorksheetSource subelements are required in the workbook HTML file. The WorksheetOptions element is specified in the corresponding worksheet HTML file as a subelement of the XML element." Here is an example: <x:ExcelWorkbook> <x:ExcelWorksheets> <x:ExcelWorksheet> <x:Name>Sheet1</x:Name> <x:WorksheetSource HRef="./Book4_files/sheet001.htm"/> </x:ExcelWorksheet> <x:ExcelWorksheet> <x:Name>Sheet2</x:Name> <x:WorksheetSource HRef="./Book4_files/sheet002.htm"/> </x:ExcelWorksheet> <x:ExcelWorksheet> <x:Name>Sheet3</x:Name> <x:WorksheetSource HRef="./Book4_files/sheet003.htm"/> </x:ExcelWorksheet> <x:ExcelWorksheet> <x:Name>MyChart</x:Name> <x:WorksheetSource HRef="./Book4_files/chart001.htm"/> <x:WorksheetType>Chart</x:WorksheetType> </x:ExcelWorksheet> </x:ExcelWorksheets> </x:ExcelWorkbook>
|
|
|
|
 |
|
 |
Hi.
I like the article. I have one problem with it though : It really is the worst way I can think of to generate Excel workbooks(reports). String building is very expensive.
'What do you suggest then?', you might ask.
The answer is : XML transformation via XSLT. Let me explain : In the field of report generation, a new strategy has emerged -> seperating report data from report format. The idea is to generate XML containing report data only, and transforming that using an XSL stylesheet. Using this strategy, you can format the report data into just about anything imaginable, including SpreadSheetML (the XML-dialect Excel uses).
I always knew engineers can't program.....just kidding (electrical engineers usually can, the rest.....stick to engineering)
|
|
|
|
 |
|
 |
I really appreciate your idea and wanted to thank you for giving me the oppurtunity to write reason for using this string manipulation technique .
You know if you use ExcelObject (PIA) Library to generate 500 worksheets by ASP.NET then better switch off your DESKTOP and go for a sleep it will not be possible .
I think this is the WORST of all methods to generate such a report.
If you use HTML pages link in a primary excel (XML) type page then your web applicaiton users will come to you daily as they will not able to download the report straight way.
Another Wrost thing.
And if you use XSLT file and XML file . and Give users Excel type XML file as download Then MS Excel will ask your option before opening the XML file for to Apply XSLT and your end users will really make you crazy because they do not understand XML XSLT etc.
And If you write and XML string load it in memory and then apply XSLT and then again save it xls for such huge chunk of data then it is better
to use string
Why ?? here are few benefits
(1)the string is the final output is Excel compatible data and you can keep building and writing it in file simultaneously
(2) debugging becomes very easy
(3) if any new feature is requested you can give it in a very short span of time , this is very important because excel has too much capabiliuty of styles ( like bold , border merging ) and this can be done much easily in string manipulation
I hope the reasons which i gave you is enough to convince you that this method is not the worst one but surely not the best one.
Was it too Electrifying bye
dekajp@yahoo.com.
|
|
|
|
 |
|
 |
what the heck are you talking about? Users being asked about XSLT? That doesn't happen if you know how to program!
Using XSLT is a simple way (besides writing the XSL needed) to transform XML from one form to another. No users are contacted, nothing out of the ordinary happens. Just run the XSL transform and you've got a new XML set. Tada!
String builder gets the job done, but it could be more elegant with XSL. The actual transform is then left to the XSL and not embedded within the code. Building strings never appealed to me. Also, having "+" concatenators, as you do in your append statements are very expensive. If you're iterating through thousands of records doing that, you're likely to get some serious delays.
|
|
|
|
 |
|
 |
Excellent article, but you should definately be using the stringbuilder instead of string concatenation, especially if you are generating very long strings.
The performance benefits should be impressive.
Huw
|
|
|
|
 |