0

私はExcelシートを作成し、使用して保存しました

xlWorkBook.SaveCopyAs("abc.xls");

それから私は使用しています

 byte[] byteArray = File.ReadAllBytes("abc.xls");
 File.Delete("abc.xls");
 Response.ContentType = "application/vnd.ms-excel";
 Response.AppendHeader("Content-Disposition", "attachment; filename=abc.xls");
 Response.BinaryWrite(byteArray);
 Response.End();

応答として Excel シートを送信します。

しかし、問題はクライアント側にあり、最初にExcelワークブック「Book1」を保存するように求められ、次に「abc.xls」を保存するように求められます。それを防ぐ方法は?

以前私が使用していた

xlWorkBook.SaveAs("abc.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

正常に動作していました(「abc.xls」を保存するように直接促されます)。しかし、IISにデプロイすると例外がスローされたxlWorkBook.SaveCopyAs()ため、に変更しまし たxlWorkBook.SaveAs()

4

1 に答える 1

0

私は自分のコードを持っています

    string fileName = "xyz.xls";

    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.ClearHeaders();
    HttpContext.Current.Response.ClearContent();
    HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", fileName));
    HttpContext.Current.Response.ContentType = "application/vnd.xls";           

    /*      
    using (StringWriter sw = new StringWriter())
    {
        using (HtmlTextWriter htw = new HtmlTextWriter(sw))
        {
            //extract
        }
    }
    */


    HttpContext.Current.Response.Write(sw.ToString());
    HttpContext.Current.Response.Flush();
    HttpContext.Current.Response.End();
于 2012-12-14T12:20:40.183 に答える