WebページからExcelにデータをエクスポートしています。これは簡単ではありませんが、データには<p>
というタグがあります。これにより、データがすべて同じセル内にあるときにExcelが新しい行を作成します。いくつかの研究の後、私はmso-data-placementがトリックを行うべきであることを発見しましたが、それは機能しません。 Excelが開き、データが表示されますが、余分な行が作成されます。ここで私はデータをエクスポートするために使用するコードは次のとおりです。mso-data-placement:同じセルが動作しない
protected void doexcel()
{
string style = @"<style type='text/css'>P {mso-data-placement:same-cell; font-weight:bold;}</style>";
HttpResponse response = HttpContext.Current.Response;
// first let's clean up the response.object
response.Clear();
response.Charset = "";
//set the response mime type for excel
response.ContentType = "application/vnd.ms-excel";
Random RandomClass = new Random();
int RandomNumber = RandomClass.Next();
String filename = "a" + RandomNumber + DateTime.Now + ".xls";
response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
// create a string writer
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
HttpContext.Current.Response.Write(style);
SqlDataSourceEmployeeAssets.ConnectionString = MyObjects.Application.CurrentContext.ConnectionString;
String sql = (string)Session["sql"];
SqlDataSourceEmployeeAssets.SelectCommand = sql;
// lCount.Text = "Query returned " + getCount(query) + " rows.";
DataGrid dge = new DataGrid();
dge.DataSource = SqlDataSourceEmployeeAssets;
dge.DataBind();
dge.RenderControl(htw);
response.Write(sw.ToString());
response.End();
}
}
}
これは私に悲しみを与えているデータベース内の生データの例である:
<P>4/13/2011 : Cheng "Jonathan" Vaing is with BSES Graffiti Unit.</P><P>4/13/2011 : Cheng "Jonathan" Vaing is with</P>
提案?
私は
- 他の物事のカップルを試してみました、私はまっすぐに、データへ行き、段落タグをインラインにMSO-データ配置属性を追加しました。まだ動作しませんでした。データは、私はどちらか動作しませんでした他のmso- *属性は、試してみました。この
<P style="mso-data-placement:same-cell> my data </p>
- のように見えました。例えば、私はこのああ、なぜExcelが認識しないのはなぜ
<style type='text/css'>P {mso-highlight:yellow}</style>";
私mso- *属性のように見えるために私のスタイルシートを変更しました?!?!