本文介绍了使用Excel时出现IIS问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的应用程序(ASP.NET,C#.NET)中,报告采用excel格式.在一个工作簿中,有两张纸,其中一张正在处理另一张工作簿...
在本地它运行良好,最后一天我将应用程序部署在IIS中,从那儿我拿到了报告,在该工作簿中显示了一张工作表.​​..最初创建的,另一张工作表(从另一工作簿复制的)不来...不被复制. IIS配置是否存在任何问题(我已经完成了正常配置).还是用代码?请帮帮我.

提前谢谢...
问候
murty

Hi,

in my application(ASP.NET,C#.NET), report comes in excel format. In one workbook, two sheets are there, in that one sheet is coping from another work book...
locally it is working fine, last day i have deployed my application in IIS, from there i have taken the report, in that workbook one sheet it is showing...which is originally created, another sheet(which is copied from another workbook) is not coming...not copied. Is there any problem with IIS configuration(I have done normal configuration). or in code? Please help me.

Thanks in advance...
Regards
murty

推荐答案


string fileName="QA Report Day Ending " + DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year.ToString() +  ".xls";
            string fName = Server.MapPath(@"Backup\") + fileName;
            string newFileName = fName;
            string oldFileName = Server.MapPath(@"Template\ParentFile.xls");
            File.Copy(oldFileName, newFileName, true);



步骤2:创建XML格式



Step 2: Creating XML format

const string startExcelXML = "<xml version=\"\">\r\n<Workbook " +

          "xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\r\n" +

          " xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\n " +

          "xmlns:x=\"urn:schemas-    microsoft-com:office:" +

          "excel\"\r\n xmlns:ss=\"urn:schemas-microsoft-com:" +

          "office:spreadsheet\">\r\n <Styles>\r\n " +
          "<Style ss:ID=\"Default\" ss:Name=\"Normal\">\r\n " +
          "<Alignment ss:Vertical=\"Bottom\"/>\r\n <Borders/>" +
          "\r\n <Font/>\r\n <Interior/>\r\n <NumberFormat/>" +
          "\r\n <Protection/>\r\n </Style>\r\n " 


const string endExcelXML = "</Workbook></xml >";
       myHtml.Append(startExcelXML);
       myHtml.Append("<ss:Worksheet ss:Name=\"Detail QA Report\">");
       myHtml.Append("<ss:Table>");
       myHtml.Append("<ss:Column ss:Width='100'/>");
       myHtml.Append("<ss:Column ss:Width='150'/>");
       myHtml.Append("<ss:Column ss:Width='100'/>");


myHtml.Append("<ss:Cell ss:StyleID=\"s41\">" +
                                       "<ss:Data ss:Type=\"String\">");
                        myHtml.Append("This is the First Row");
                        myHtml.Append("</ss:Data></ss:Cell>");


myHtml.Append(</ss:Table>");
myHtml.Append(");
myHtml.Append(</ss:Worksheet>");

步骤3:用于复制的工作表

app = new Application();
app.Visible = false;
workbook = app.Workbooks.Open(newFileName,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing, Type.Missing,Type.Missing,Type.Missing,Type.Missing);
baseWorkBook = app.Workbooks.Open(原始文件名,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing, Type.Missing,Type.Missing,Type.Missing,Type.Missing);
工作表sheetSummary = new Worksheet();
baseWorkBook.Worksheets.Copy(workbook.Worksheets [1],Type.Missing);
baseWorkBook.Save();
表格xlSheets = workbook.Sheets as Sheets;
sheetSummary =(工作表)xlSheets [1];
sheetSummary.Cells [12,2] =质量检查报告结束日:" + txtEndDate.Text.ToString();


myHtml.Append("</ss:Table>");
myHtml.Append("");
myHtml.Append(" </ss:Worksheet>");

Step 3: for copied work sheet

app = new Application();
app.Visible = false;
workbook = app.Workbooks.Open(newFileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
baseWorkBook = app.Workbooks.Open(originalFileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
Worksheet sheetSummary = new Worksheet();
baseWorkBook.Worksheets.Copy(workbook.Worksheets[1],Type.Missing);
baseWorkBook.Save();
Sheets xlSheets = workbook.Sheets as Sheets;
sheetSummary = (Worksheet)xlSheets[1];
sheetSummary.Cells[12, 2] = "QA Report Day Ending: "+ txtEndDate.Text.ToString();

workbook.Save();
            workbook.Close(false, Type.Missing, Type.Missing);
            baseWorkBook.Save();
            baseWorkBook.Close(false, Type.Missing, Type.Missing);
            app.Quit();




这就是我所做的,它可以在本地系统上完美运行...我希望,在IIS中,工作簿不会打开或不复制工作表...




This is what i have done,it is working on local system perfectly...I hope,in the IIS the workbook is not opening or not copying the worksheet...


这篇关于使用Excel时出现IIS问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 21:19