Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created Excel file using of this code.

C#
private static string getWorksheets(DataSet source)
        {   int DataTableIncrement = 0;
              string str = "NameDisplay";
            var sw = new StringWriter();
            sw.Write("<Worksheet ss:Name=\"SoftwareListReport.xls\"><Table><Row><Cell  ss:StyleID=\"s62\"><Data ss:Type=\"String\"></Data></Cell></Row> ");//</Table></Worksheet>

            if (source == null || source.Tables.Count == 0)
            {
                sw.Write("<Worksheet ss:Name=\"SoftwareListReport\"><Table><Row><Cell  ss:StyleID=\"s62\"><Data ss:Type=\"String\"></Data> </Cell></Row></Table></Worksheet>");
                return sw.ToString();
            }
            foreach (DataTable dt in source.Tables)
            {

                if (dt.Rows.Count == 0)
                    sw.Write("<Worksheet ss:Name=\"" + replaceXmlChar(dt.TableName) + "\"><Table><Row><Cell  ss:StyleID=\"s62\"><Data ss:Type=\"String\"></Data></Cell></Row>");// </Table></Worksheet>
                else
                {
                    
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        if ((i % rowLimit) == 0)
                        {
                          
                            if (DataTableIncrement == 0)
                            {
                                sw.Write("<Row>");
                                foreach (DataColumn dc in dt.Columns)
                                {
                                    sw.Write(string.Format( "<Cell ss:StyleID=\"BoldColumn\"><Data ss:Type=\"String\">{0}</Data></Cell>",replaceXmlChar(dc.ColumnName)));
                                }
                                sw.Write("</Row>\r\n");
                            }
                            else
                            {
                                sw.Write("<Row>");
                                foreach (DataColumn dc in dt.Columns)
                                {
                                    if (dc.ColumnName == str)
                                    {
                                        sw.Write(
                                            string.Format(
                                                "<Cell ss:StyleID=\"BoldColumn\"><Data ss:Type=\"String\">{0}</Data></Cell>",
                                                replaceXmlChar("")));
                                    }
                                } sw.Write("</Row>\r\n");
                            }
                        }
                        if (DataTableIncrement == 0)
                        {
                            sw.Write("<Row>\r\n");
                            foreach (DataColumn dc in dt.Columns)
                            {
                                sw.Write(
                                    string.Format("<Cell ss:StyleID=\"s62\"><Data ss:Type=\"String\">{0}</Data></Cell>",
                                                replaceXmlChar(dt.Rows[i][dc.ColumnName].ToString())));
                            }
                            sw.Write("</Row>\r\n");
                        }
                        else
                        {
                            sw.Write("<Row>\r\n");
                            foreach (DataColumn dc in dt.Columns)
                            {
                                if (dc.ColumnName == str)
                                {
                                    sw.Write(
                                        string.Format("<Cell ss:StyleID=\"s62\"><Data ss:Type=\"String\">{0}</Data></Cell>",
                                                    replaceXmlChar(dt.Rows[i][dc.ColumnName].ToString())));
                                }

                            } sw.Write("</Row>\r\n");
                        }                         
                    }
                    DataTableIncrement++;                    
                }
            } 
            sw.Write("</Table></Worksheet>");
            return sw.ToString();
        }

when i click on cell (software name) then it will move other cell which have same software name in same excel sheet. how to do this using of ASP.NET CODE WITH C#
Posted
Updated 13-Feb-12 21:57pm
v2
Comments
E.F. Nijboer 14-Feb-12 3:57am    
That's a lot of code you posted here and it is still unclear to me what the problem is. Could you please add more info, strip your code to the bare minimum and put code tags around it? Thanks! :-)
Amod Kumar Jaiswal 14-Feb-12 4:04am    
JUST I WANT TO ADD HYPER LINK IN EXCEL CELL.WHEN I CLICK ON THAT CELL IT WILL MOVE ON SIMILAR TEXT IN SAME SHEET.
Herman<T>.Instance 14-Feb-12 4:09am    
don't SHOUT! thats rude
manognya kota 14-Feb-12 4:15am    
Hi Amod,
Please do not reply in capital letters.It means you are shouting..
Amod Kumar Jaiswal 14-Feb-12 4:17am    
ok. i don't know about that thank's

Read this article below for your reference

Fast-Exporting-from-DataSet-to-Excel
Forums in ASP.NET
csharpcorner
Export-a-DataSet-to-Microsoft-Excel-without-the-us

Vote or Accept Solution
if this will help you
thanks
 
Share this answer
 
Comments
Amod Kumar Jaiswal 14-Feb-12 6:07am    
i did already but i want add hyperlink in cell for moving one cell to anther cell in the same sheet.

plz if u can help me how to write it in cell.
I think the following link to stackoverflow might have something useful. Check it out: http://stackoverflow.com/questions/2905633/add-hyperlink-to-cell-in-excel-2007-using-open-xml-sdk-2-0[^]

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900