Hello,

I have created an HTML table wherein the row's values are filled thru database.
ex: FirstName : dbvalue and so on...

Then i create an excel file please find below code:

StringBuilder str1 = new StringBuilder();
str1.Append("<html xmlns:o='urn:schemas-microsoft-com:office:office'").Append(Environment.NewLine);
str1.Append("xmlns:x='urn:schemas-microsoft-com:office:excel'").Append(Environment.NewLine);
str1.Append("xmlns='http://www.w3.org/TR/REC-html40'>").Append(Environment.NewLine);
str1.Append(Environment.NewLine);
str1.Append("<head>").Append(Environment.NewLine);
str1.Append("<meta http-equiv=Content-Type content='text/html; charset=windows-1252'>").Append(Environment.NewLine);
str1.Append("<meta name=ProgId content=Excel.Sheet>").Append(Environment.NewLine);
str1.Append("<meta name=Generator content='Microsoft Excel 11'>").Append(Environment.NewLine);
str1.Append(Environment.NewLine);
str1.Append("<title>Time</title>").Append(Environment.NewLine);
str1.Append("<!--[if gte mso 9]><xml>").Append(Environment.NewLine);
str1.Append("<o:DocumentProperties>").Append(Environment.NewLine);
str1.Append("<o:LastAuthor>rohanl</o:LastAuthor>").Append(Environment.NewLine);
str1.Append("<o:Created>2003-01-01T18:48:00Z</o:Created>").Append(Environment.NewLine);
str1.Append("<o:LastSaved>2003-01-01T21:11:56Z</o:LastSaved>").Append(Environment.NewLine);
str1.Append("<o:Version>11.9999</o:Version>").Append(Environment.NewLine);
str1.Append("</o:DocumentProperties>").Append(Environment.NewLine);
str1.Append("</xml><![endif]-->").Append(Environment.NewLine);
str1.Append(Environment.NewLine);
str1.Append("<!--[if gte mso 9]><xml>").Append(Environment.NewLine);
str1.Append("<x:ExcelWorkbook>").Append(Environment.NewLine);
str1.Append("<x:ExcelWorksheets>").Append(Environment.NewLine);
str1.Append("<x:ExcelWorksheet>").Append(Environment.NewLine);
str1.Append("<x:Name>Employee_Details</x:Name>").Append(Environment.NewLine);
str1.Append("<x:WorksheetOptions>").Append(Environment.NewLine);
str1.Append("<x:Print>").Append(Environment.NewLine);
str1.Append("<x:ValidPrinterInfo/>").Append(Environment.NewLine);
str1.Append("<x:HorizontalResolution>200</x:HorizontalResolution>").Append(Environment.NewLine);
str1.Append("<x:VerticalResolution>200</x:VerticalResolution>").Append(Environment.NewLine);
str1.Append("</x:Print>").Append(Environment.NewLine);
str1.Append("<x:Selected/>").Append(Environment.NewLine);
str1.Append("<x:DoNotDisplayGridlines/>").Append(Environment.NewLine);
str1.Append("<x:ProtectContents>False</x:ProtectContents>").Append(Environment.NewLine);
str1.Append("<x:ProtectObjects>False</x:ProtectObjects>").Append(Environment.NewLine);
str1.Append("<x:ProtectScenarios>False</x:ProtectScenarios>").Append(Environment.NewLine);
str1.Append("</x:WorksheetOptions>").Append(Environment.NewLine);
str1.Append("</x:ExcelWorksheet>").Append(Environment.NewLine);
str1.Append("</x:ExcelWorksheets>").Append(Environment.NewLine);
str1.Append("<x:WindowHeight>8190</x:WindowHeight>").Append(Environment.NewLine);
str1.Append("<x:WindowWidth>19035</x:WindowWidth>").Append(Environment.NewLine);
str1.Append("<x:WindowTopX>0</x:WindowTopX>").Append(Environment.NewLine);
str1.Append("<x:WindowTopY>15</x:WindowTopY>").Append(Environment.NewLine);
str1.Append("<x:ProtectStructure>False</x:ProtectStructure>").Append(Environment.NewLine);
str1.Append("<x:ProtectWindows>False</x:ProtectWindows>").Append(Environment.NewLine);
str1.Append("</x:ExcelWorkbook>").Append(Environment.NewLine);
str1.Append("</xml><![endif]-->").Append(Environment.NewLine);
str1.Append("</head>").Append(Environment.NewLine);
str1.Append(Environment.NewLine);
str1.Append("<body lang=EN-US style='mso-element:header' id=h1>").Append(Environment.NewLine);
str1.Append("<span style='mso--code:DATE'></span>").Append(Environment.NewLine);
str1.Append(str.ToString()).Append(Environment.NewLine);
str1.Append("</body>").Append(Environment.NewLine);
str1.Append("</html>");
return str1;

AFTER THIS I SEND THIS FILE CREATED VIA ATTACHMENT....( THAT CODE I HAVE NOT INSERTED HERE)

I GET THE MAIL ALONG WITH ATTACHMENT. HOWEVER, WHEN I TRY TO OPEN THIS ATTACHMENT I GET ERROR :

"THIS FILE IS NOT IN RECOGNIZABLE FORMAT".

WHAT IS THE PROBLEM?? WHY THE FILE IS NOT RECOGNIZABLE?? please give me solution...please.

SECONDLY, WHEN I GET THE MESSAGE : "THIS FILE IS NOT IN RECOGNIZABLE FORMAT".
I just click ctrl + S and close the file and again Open it i am ABLE TO OPEN THE FILE WITHOUT ANY ERROR...

PLEASE SUGGEST ME THE SOLUTION AT EARLIEST.

AWATING EARLIEST REPLY....

THANKING YOU,

ROHAN

It may be too late for this now (as I think the edit option only remains for a short time after posting and definitely not after a reply has been made) but in future when posting code like above I'd recommend either using the code formatting option (instead of quote) or deselecting the option that displays smileys in your post (at the bottom below the post creation button.

As it stands right now a large amount of your code segment above is filled with smileys which makes it harder to read through what's being done.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.