0

私は初心者で、変換方法がわかりません。

これが私のコードです:

Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename=" + filename + ".xls");
Response.ContentType = "application/vnd.ms-excel";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Charset = "";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
Response.ContentEncoding = System.Text.Encoding.Unicode;
fuFile.RenderControl(hw);
Response.Output.Write(sw.ToString().Replace(" ", "").Replace("&", "&"));
Response.End();

これは、HTML ファイルを Excel にエクスポートするのに十分ではありませんか?

4

1 に答える 1

2

私はこれがうまくいくことを発見しました:

String content = "<html><body><table><tr><td>your table</td></tr></table></body></html>";

Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename=" + filename + ".xls");
Response.ContentType = "application/vnd.xls";
Response.Cache.SetCacheability(HttpCacheability.NoCache); // not necessarily required
Response.Charset = "";
Response.Output.Write(content);
Response.End();

コンテンツが整形式の HTML である限り、これは機能するはずです。また、コメント、VBA コード/マクロ、および複数のワークシートは、この方法では機能しないことに注意してください。さらに、インラインでないスタイリングもレンダリングされません。

この問題に関するその他の考慮事項: Web ページhttp://www.c-sharpcorner.com/UploadFile/ankurmalik123/export-html-to-excel-and-more/
からテーブルをエクスポートして Excel にするにはどうすればよいですか?

于 2013-11-19T19:04:08.167 に答える