.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 10th, 2008, 11:04 AM
rameshwar rameshwar is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 2 rameshwar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 32 sec
Reputation Power: 0
<Workbook> Support in Excel Version 2000

As I am also trying to export the data into excel using
the following stmt

public System.IO.StringWriter ExportToExcelXML(DataSet source)
{

System.IO.StringWriter excelDoc;



excelDoc = new System.IO.StringWriter();

StringBuilder ExcelXML = new StringBuilder();

ExcelXML.Append("<xml version>\r\n<Workbook ");

ExcelXML.Append("xmlns=\"urn:schemas-microsoft-comffice:spreadsheet\"\r\n");

ExcelXML.Append(" xmlns=\"urn:schemas-microsoft-comfficeffice\"\r\n ");

ExcelXML.Append("xmlns:x=\"urn:schemas- microsoft-comffice:");

ExcelXML.Append("excel\"\r\n xmlns:ss=\"urn:schemas-microsoft-com:");

ExcelXML.Append("office:spreadsheet\">\r\n <Styles>\r\n ");

ExcelXML.Append("<Style ss:ID=\"Default\" ss:Name=\"Normal\">\r\n ");

ExcelXML.Append("<Alignment ss:Vertical=\"Bottom\"/>\r\n <Borders/>");

ExcelXML.Append("\r\n <Font/>\r\n <Interior/>\r\n <NumberFormat/>");

ExcelXML.Append("\r\n <Protection/>\r\n </Style>\r\n ");

ExcelXML.Append("<Style ss:ID=\"BoldColumn\">\r\n <Font ");

ExcelXML.Append("x:Family=\"Swiss\" ss:Bold=\"1\"/>\r\n </Style>\r\n ");

ExcelXML.Append("<Style ss:ID=\"StringLiteral\">\r\n <NumberFormat");

ExcelXML.Append(" ss:Format=\"@\"/>\r\n </Style>\r\n <Style ");

ExcelXML.Append("ss:ID=\"Decimal\">\r\n <NumberFormat ");

ExcelXML.Append("ss:Format=\"0.0000\"/>\r\n </Style>\r\n ");

ExcelXML.Append("<Style ss:ID=\"Integer\">\r\n <NumberFormat ");

ExcelXML.Append("ss:Format=\"0\"/>\r\n </Style>\r\n <Style ");

ExcelXML.Append("ss:ID=\"DateLiteral\">\r\n <NumberFormat ");
ExcelXML.Append("ss:Format=\"mm/dd/yyyy;@\"/>\r\n </Style>\r\n ");

ExcelXML.Append("<Style ss:ID=\"s28\">\r\n");

ExcelXML.Append("<Alignment ss:Horizontal=\"Left\" ss:Vertical=\"Top\" ss:ReadingOrder=\"LeftToRight\" ss:WrapText=\"1\"/>\r\n");

ExcelXML.Append("<Font x:CharSet=\"1\" ss:Size=\"9\" ss:Color=\"#808080\" ss:Underline=\"Single\"/>\r\n");

ExcelXML.Append("<Interior ss:Color=\"#D3D3D3\" ss:Pattern=\"Solid\"/></Style>\r\n");

ExcelXML.Append("</Styles>\r\n ");

string startExcelXML = ExcelXML.ToString();

const string endExcelXML = "</Workbook>";

int rowCount = 0;

int sheetCount = 1;

excelDoc.Write(startExcelXML);

excelDoc.Write("<Worksheet ss:Name=\"Report_Sheet" + sheetCount + "\">");

excelDoc.Write("<Table>");

// excelDoc.Write("<Row ss:AutoFitHeight=\"0\" ss:Height=\"6.75\"/>\r\n");

excelDoc.Write("<Row ><Cell ss:MergeAcross=\"10\"><Data ss:Type=\"String\">");

excelDoc.Write("HEADER TEXT");

excelDoc.Write("</Data></Cell>");

excelDoc.Write("<Cell ss:MergeAcross=\"1\" ss:StyleID=\"BoldColumn\"><Data ss:Type=\"String\">");

excelDoc.Write("Report Date");

excelDoc.Write("</Data></Cell>");

excelDoc.Write("<Cell ss:MergeAcross=\"1\" ss:StyleID=\"DateLiteral\"><Data ss:Type=\"String\">");

excelDoc.Write(DateTime.Now.ToShortDateString());

excelDoc.Write("</Data></Cell></Row>");

// excelDoc.Write("<Row ss:AutoFitHeight=\"0\" ss:Height=\"10\"/>\r\n");

///Complete

excelDoc.Write("<Row ss:StyleID=\"s28\">");

for (int x = 0; x < source.Tables[0].Columns.Count; x++)
{

excelDoc.Write("<Cell ss:StyleID=\"BoldColumn\"><Data ss:Type=\"String\">");

excelDoc.Write(source.Tables[0].Columns[x].ColumnName);

excelDoc.Write("</Data></Cell>");

}

excelDoc.Write("</Row>");

foreach (DataRow x in source.Tables[0].Rows)
{

rowCount++;

//if the number of rows is > 63000 create a new page to continue output

if (rowCount == 63000)
{

rowCount = 0;

sheetCount++;

excelDoc.Write("</Table>");

excelDoc.Write(" </Worksheet>");

excelDoc.Write("<Worksheet ss:Name=\"Report_Sheet" + sheetCount + "\">");

excelDoc.Write("<Table>");



excelDoc.Write("<Row>");

for (int xi = 0; xi < source.Tables[0].Columns.Count; xi++)
{


excelDoc.Write("<Cell ss:StyleID=\"BoldColumn\"><Data ss:Type=\"String\">");




excelDoc.Write(source.Tables[0].Columns[xi].ColumnName);

excelDoc.Write("</Data></Cell>");

}

excelDoc.Write("</Row>");

}

excelDoc.Write("<Row>");

for (int y = 0; y < source.Tables[0].Columns.Count; y++)
{

string XMLstring = x[y].ToString();

XMLstring = XMLstring.Trim();

XMLstring = XMLstring.Replace("&", "&");

XMLstring = XMLstring.Replace(">", ">");

XMLstring = XMLstring.Replace("<", "<");


excelDoc.Write("<Cell ss:StyleID=\"StringLiteral\">" +
"<Data ss:Type=\"String\">");


excelDoc.Write(XMLstring);

excelDoc.Write("</Data></Cell>");

}

excelDoc.Write("</Row>");

}

excelDoc.Write("</Table>");

excelDoc.Write(" </Worksheet>");


excelDoc.Write(endExcelXML);

return excelDoc;

}

protected void lnkExcel_Click(object sender, System.EventArgs e)
{

DataSet ds = new DataSet();
ds.Tables.Add("Customers");
ds.Tables[0].Columns.Add("CustomerID");
ds.Tables[0].Columns.Add("CompanyName");
ds.Tables[0].Columns.Add("CompanyLOGO");
ds.Tables[0].Columns.Add("CompanyAddress");
ds.Tables[0].Columns.Add("CompanyPhone");
ds.Tables[0].Columns.Add("CompanyEmailID");
ds.Tables[0].Columns.Add("CompanyFAX");
ds.Tables[0].Columns.Add("CompanyDETAIL");
ds.Tables[0].Columns.Add("CompanyIP");
ds.Tables[0].Columns.Add("CompanyWEB");
for (double i = 0; i <= 67000; i++)
{
DataRow newCustomersRow = ds.Tables["Customers"].NewRow();

newCustomersRow["CustomerID"] = "ALFKI"+i.ToString();
newCustomersRow["CompanyName"] = "Alfreds Futterkiste" + i.ToString();

newCustomersRow["CompanyLOGO"] = "HDFCSL";
newCustomersRow["CompanyAddress"] = "HDFCSLAdd";
newCustomersRow["CompanyPhone"] = "HDFCSLPhone";
newCustomersRow["CompanyEmailID"] = "HDFCSLEmailID";
newCustomersRow["CompanyFAX"] = "HDFCSLFAX";
newCustomersRow["CompanyDETAIL"]= "HDFCSLDETAIL";
newCustomersRow["CompanyIP"]= "HDFCSLIP";
newCustomersRow["CompanyWEB"] = "12/12/2008";
ds.Tables["Customers"].Rows.Add(newCustomersRow);
}



Response.Buffer = true;

Response.ContentType = "application/vnd.ms-excel";

Response.AddHeader("Content-Disposition", "attachment; filename=Report.xls");


this.EnableViewState = false;

Response.Charset = string.Empty;

System.IO.StringWriter myTextWriter = new System.IO.StringWriter();
myTextWriter = ExportToExcelXML(ds);


Response.Write(myTextWriter.ToString());
//File.WriteAllText(strPath, excelFile);
Response.End();
}

This is worked/support on Excel 2003 version
but it is not worked on Excel 2000 version
If you know then How it is possible to support on any version ?
or suggest any alternative way except COM interop

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > <Workbook> Support in Excel Version 2000


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap