Excel.application xlapptoexport = new excel.application()在服务器上不起作用,它在本地正常工作。 [英] Excel.application xlapptoexport = new excel.application() is not working on server, it working proper locally.

查看:67
本文介绍了Excel.application xlapptoexport = new excel.application()在服务器上不起作用,它在本地正常工作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Excel.Application xlAppToExport = new Excel.Application();

excel导出在本地工作,但不在server.i上工作,不会出现任何错误。



我尝试过:



Excel.Application xlAppToExport = new Excel。申请();



xlAppToExport.Workbooks.Add();



//添加工作表。

Excel.Worksheet xlWorkSheetToExport = default(Excel.Worksheet);

xlWorkSheetToExport =(Excel.Worksheet)xlAppToExport.Sheets [ Sheet1];



//从数据开始显示的行ID ID。

int iRowCnt = 4;



//显示标题。

xlWorkSheetToExport.Cells [1,1] =GST客户信息;



Ex cel.Range range = xlWorkSheetToExport.Cells [1,1] as Excel.Range;

range.EntireRow.Font.Name =Calibri;

range.EntireRow。 Font.Bold = true;

range.EntireRow.Font.Size = 20;





// Excel.Range ranget = xlWorkSheetToExport.Cells [1,4] as Excel.Range;

//ranget.EntireRow.Font.Name =Calibri;

// ranget.EntireRow.Font.Bold = true;

//ranget.EntireRow.Font.Size = 20;

//range.EntireRow.VerticalAlignment =Center;

xlAppToExport.get_Range(A1,A20)。Cells.Horizo​​ntalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;

xlWorkSheetToExport.Range [ A1:B1]。MergeCells = true; // HEADER的MERGE CELLS。:c1:1:1:1:1:1:1:1:1:1:1:1:$ 1 ,B20)。Cells.Horizo​​ntalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;

Excel.Range chartRange;

chartRange = xlWorkSheetToExport.get_Range( A1,A20);

chartRange.Font.Bold = true;

//在顶部显示列。

xlWorkSheetToExport .Cells [4,1] =类型;



xlWorkSheetToExport.Cells [5,1] =EmailId;

xlWorkSheetToExport .Cells [6,1] =Name;

xlWorkSheetToExport.Cells [7,1] =PANNo;

xlWorkSheetToExport.Cells [8,1] = ProGstNo;

xlWorkSheetToExport.Cells [9,1] =州;

xlWorkSheetToExport.Cells [ 10,1] =城市;

xlWorkSheetToExport.Cells [11,1] =ContactPerson;

xlWorkSheetToExport.Cells [12,1] =ContactNumber ;

xlWorkSheetToExport.Cells [13,1] =评论;

xlWorkSheetToExport.Cells [14,1] =AcHolderName;

xlWorkSheetToExport.Cells [15,1] =银行;

xlWorkSheetToExport.Cells [16,1] =分支;

xlWorkSheetToExport.Cells [17,1,1 ] =AcNumber;

xlWorkSheetToExport.Cells [18,1] =IFSCCode;

xlWorkSheetToExport.Cells [19,1] =MICRCode;

//xlWorkSheetToExport.Cells[20,1] =GstAcknowCopy;

//xlWorkSheetToExport.Cells[iRowCnt - 1,3] =PresentAddress;

//xlWorkSheetToExport.Cells[iRowCnt - 1,4] =电子邮件地址;





int i;

for(i = 0;我< = dt.Rows.Count - 1; i ++)

{

xlWorkSheetToExport.Cells [4,2] = dt.Rows [i] .Field< string>(Type);

xlWorkSheetToExport.Cells [5,2] = dt.Rows [i] .Field< string>(EmailId);

xlWorkSheetToExport.Cells [6,2] = dt.Rows [ i] .Field< string>(Name);

xlWorkSheetToExport.Cells [7,2] = dt.Rows [i] .Field< string>(PANNo);

xlWorkSheetToExport.Cells [8,2] = dt.Rows [i] .Field< string>(ProGstNo);

xlWorkSheetToExport.Cells [9,2] = dt。行[i] .Field< string>(State);

xlWorkSheetToExport.Cells [10,2] = dt.Rows [i] .Field< string>(City);

xlWorkSheetToExport.Cells [11,2] = dt.Rows [i] .Field< string>(ContactPerson);

xlWorkSheetToExport.Cells [12,2] =dt.Rows [i] .Field< string>(ContactNumber);

xlWorkSheetToExport.Cells [13,2] = dt.Rows [i] .Field< string>(Comments) ;

xlWorkSheetToExport.Cells [14,2] = dt.Rows [i] .Field< string>(AcHolderName);

xlWorkSheetToExport.Cells [15,2 ] = dt.Rows [i] .Field< string>(Bank);

xlWorkSheetToExport.Cells [16,2] = dt.Rows [i] .Field< string>(Branch );

xlWorkSheetToExport.Cells [17,2] = dt.Rows [i] .Field< string>(AcNumber);

xlWorkSheetToExport.Cells [18 ,2] = dt.Rows [i] .Field< string>(IFSCCode);

xlWorkSheetToExport.Cells [19,2] = dt.Rows [i] .Field< string>( MICRCode);

//xlWorkSheetToExport.Cells [19,2] = dt.Rows [i] .Field< string>(GstAcknowCopy);

//xlWorkSheetToExport.Cells[iRowCnt,3] = dt.Rows [i] .Field(PresentAddress);

//xlWorkSheetToExport.Cells[iRowCnt,4] = dt.Rows [i] .Field(Email);



iRowCnt = iRowCnt + 1;

}



//最后,使用EXCEL的自适应功能格式化EXCEL表。

Excel.Range range1 = xlAppToExport.ActiveCell.Worksheet.Cells [1,1] as Excel.Range;

range1.AutoFormat(ExcelAutoFormat.xlRangeAutoFormatList3);

range1.Rows.AutoFit();

range1.Columns.AutoFit();

xlAppToExport.Workbooks.Close();

xlAppToExport.Quit();

xlAppToExport = null;

xlWorkSheetToExport = null ;

解决方案

Quote:

Excel.Application xlAppToExport = new Excel.Application();

excel导出工作在本地但不工作server.i无法收到任何错误。



因为'MS Office for Server'不存在,你的服务器没有Excel!



您有要读取,修改或保存Excel文件的库,您需要符合您需要的库。


Excel.Application xlAppToExport = new Excel.Application();
excel Export working on local but not working on server.i can't getting any error.

What I have tried:

Excel.Application xlAppToExport = new Excel.Application();

xlAppToExport.Workbooks.Add("");

// ADD A WORKSHEET.
Excel.Worksheet xlWorkSheetToExport = default(Excel.Worksheet);
xlWorkSheetToExport = (Excel.Worksheet)xlAppToExport.Sheets["Sheet1"];

// ROW ID FROM WHERE THE DATA STARTS SHOWING.
int iRowCnt = 4;

// SHOW THE HEADER.
xlWorkSheetToExport.Cells[1, 1] = "GST Information For Customer";

Excel.Range range = xlWorkSheetToExport.Cells[1, 1] as Excel.Range;
range.EntireRow.Font.Name = "Calibri";
range.EntireRow.Font.Bold = true;
range.EntireRow.Font.Size = 20;


//Excel.Range ranget = xlWorkSheetToExport.Cells[1, 4] as Excel.Range;
//ranget.EntireRow.Font.Name = "Calibri";
//ranget.EntireRow.Font.Bold = true;
//ranget.EntireRow.Font.Size = 20;
//range.EntireRow.VerticalAlignment = "Center";
xlAppToExport.get_Range("A1", "A20").Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;
xlWorkSheetToExport.Range["A1:B1"].MergeCells = true; // MERGE CELLS OF THE HEADER.:c1:d1:e1:f1:g1:h1:i1:j1:k1:l1:m1:n1:o1:p1
xlAppToExport.get_Range("B1", "B20").Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;
Excel.Range chartRange;
chartRange = xlWorkSheetToExport.get_Range("A1", "A20");
chartRange.Font.Bold = true;
// SHOW COLUMNS ON THE TOP.
xlWorkSheetToExport.Cells[4, 1] = "Type";

xlWorkSheetToExport.Cells[5, 1] = "EmailId";
xlWorkSheetToExport.Cells[6, 1] = "Name";
xlWorkSheetToExport.Cells[7, 1] = "PANNo";
xlWorkSheetToExport.Cells[8, 1] = "ProGstNo";
xlWorkSheetToExport.Cells[9, 1] = "State";
xlWorkSheetToExport.Cells[10, 1] = "City";
xlWorkSheetToExport.Cells[11, 1] = "ContactPerson";
xlWorkSheetToExport.Cells[12, 1] = "ContactNumber";
xlWorkSheetToExport.Cells[13, 1] = "Comments";
xlWorkSheetToExport.Cells[14, 1] = "AcHolderName";
xlWorkSheetToExport.Cells[15, 1] = "Bank";
xlWorkSheetToExport.Cells[16, 1] = "Branch";
xlWorkSheetToExport.Cells[17, 1] = "AcNumber";
xlWorkSheetToExport.Cells[18, 1] = "IFSCCode";
xlWorkSheetToExport.Cells[19, 1] = "MICRCode";
//xlWorkSheetToExport.Cells[20, 1] = "GstAcknowCopy";
//xlWorkSheetToExport.Cells[iRowCnt - 1, 3] = "PresentAddress";
//xlWorkSheetToExport.Cells[iRowCnt - 1, 4] = "Email Address";


int i;
for (i = 0; i <= dt.Rows.Count - 1; i++)
{
xlWorkSheetToExport.Cells[4, 2] = dt.Rows[i].Field<string>("Type");
xlWorkSheetToExport.Cells[5, 2] = dt.Rows[i].Field<string>("EmailId");
xlWorkSheetToExport.Cells[6, 2] = dt.Rows[i].Field<string>("Name");
xlWorkSheetToExport.Cells[7, 2] = dt.Rows[i].Field<string>("PANNo");
xlWorkSheetToExport.Cells[8, 2] = dt.Rows[i].Field<string>("ProGstNo");
xlWorkSheetToExport.Cells[9, 2] = dt.Rows[i].Field<string>("State");
xlWorkSheetToExport.Cells[10, 2] = dt.Rows[i].Field<string>("City");
xlWorkSheetToExport.Cells[11, 2] = dt.Rows[i].Field<string>("ContactPerson");
xlWorkSheetToExport.Cells[12, 2] = dt.Rows[i].Field<string>("ContactNumber");
xlWorkSheetToExport.Cells[13, 2] = dt.Rows[i].Field<string>("Comments");
xlWorkSheetToExport.Cells[14, 2] = dt.Rows[i].Field<string>("AcHolderName");
xlWorkSheetToExport.Cells[15, 2] = dt.Rows[i].Field<string>("Bank");
xlWorkSheetToExport.Cells[16, 2] = dt.Rows[i].Field<string>("Branch");
xlWorkSheetToExport.Cells[17, 2] = dt.Rows[i].Field<string>("AcNumber");
xlWorkSheetToExport.Cells[18, 2] = dt.Rows[i].Field<string>("IFSCCode");
xlWorkSheetToExport.Cells[19, 2] = dt.Rows[i].Field<string>("MICRCode");
//xlWorkSheetToExport.Cells[19, 2] = dt.Rows[i].Field<string>("GstAcknowCopy");
//xlWorkSheetToExport.Cells[iRowCnt, 3] = dt.Rows[i].Field("PresentAddress");
//xlWorkSheetToExport.Cells[iRowCnt, 4] = dt.Rows[i].Field("Email");

iRowCnt = iRowCnt + 1;
}

// FINALLY, FORMAT THE EXCEL SHEET USING EXCEL'S AUTOFORMAT FUNCTION.
Excel.Range range1 = xlAppToExport.ActiveCell.Worksheet.Cells[1, 1] as Excel.Range;
range1.AutoFormat(ExcelAutoFormat.xlRangeAutoFormatList3);
range1.Rows.AutoFit();
range1.Columns.AutoFit();
xlAppToExport.Workbooks.Close();
xlAppToExport.Quit();
xlAppToExport = null;
xlWorkSheetToExport = null;

解决方案

Quote:

Excel.Application xlAppToExport = new Excel.Application();
excel Export working on local but not working on server.i can't getting any error.


Because 'MS Office for Server' does not exist, your server don't have Excel !

You have libraries to read, modify or save an Excel file, you need to the one that fit your needs.


这篇关于Excel.application xlapptoexport = new excel.application()在服务器上不起作用,它在本地正常工作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆