Wenn man Daten über eine Webseite zu Excel exportieren will, geht das eigentlich ganz einfach, indem man eine HTML Seite ausgibt, die eine Tabelle enthält, und dann den Contentyp setzt.
Dazu kann man noch den Tabellenzellen bestimmte CSS Attribute mitgeben, so dass die dann von Excel auch passent erkannt werden.
Hier mal ein ganz grober Dummy, der aber das Vorgehen veranschaulicht:
Response.Clear()Response.ClearHeaders()Response.ContentEncoding = Encoding.DefaultResponse.Buffer = TrueResponse.ContentType = "application/vnd.ms-excel"Response.AddHeader("Content-Disposition", "inline; filename=Statistik.xls")Dim Out As New StringBuilderOut.Append("<html>")Out.Append("<style>")Out.Append("body,th,td{font-size:10px;font-family:arial;color:black;}")Out.Append("table{mso-displayed-decimal-separator:""\,"";mso-displayed-thousand-separator:""\."";}")Out.Append("td{padding-top:1px;padding-right:1px;padding-left:1px;mso-ignore:padding;color:black;font-size:10.0pt;font-weight:400;font-style:normal;text-decoration:none;font-family:Calibri,sans-serif;mso-font-charset:0;mso-number-format:General;text-align:left;vertical-align:top;mso-background-source:auto;mso-pattern:auto;white-space:normal;}")Out.Append(".th{background:#d8d8d8;font-size:10px;font-family:arial;color:black;mso-pattern:black none;}")Out.Append(".date{mso-number-format:""Short Date"";}")Out.Append("</style>")Out.Append("<body>")Out.Append("<table>")Out.Append("<tr>")Out.Append("<td class='.date' align='left'>7.4.2009</th>")Out.Append("</tr>")Out.Append("</table>")Out.Append("</body>")Out.Append("</html>")Response.Write(Out.ToString)Response.End()
Folgende Formatierungsmöglichkeiten hat man für mso-number-format:
"0" NO Decimals "0\.000" 3 Decimals "\#\,\#\#0\.000" Comma with 3 dec "mm\/dd\/yy" Date7 "mmmm\ d\,\ yyyy" Date9 "m\/d\/yy\ h\:mm\ AM\/PM" D -T AMPM "Short Date" 01/03/1998 "Medium Date" 01-mar-98 "d\-mmm\-yyyy" 01-mar-1998 "Short Time" 5:16 "Medium Time" 5:16 am "Long Time" 5:16:21:00 "Percent" Percent - two decimals "0%" Percent - no decimals "0\.E+00" Scientific Notation "\@" Text "\#\ ???\/???" Fractions - up to 3 digits (312/943) "\0022£\0022\#\,\#\#0\.00" £12.76 "\#\,\#\#0\.00_ \;\[Red\]\-\#\,\#\#0\.00\ " 2 decimals, negative numbers in red and signed (1.56 -1.56)
6113bb6c-9995-461c-b33f-3a6247497baf|1|5.0