Regarding ASPX to guide Excel, there are many online methods, and the most important thing is to use COM's control. The younger brother used to have such a method before. Some kind of complex registration, and may be slower in terms of efficiency, so the younger brother used a method of changing, the effect is not bad, dare not stay alone, so share it with everyone.
We know that there is a very big benefit in the web program is that as long as the configuration on the server, you can not consider the client's stuff. The main idea of this program is to generate related operations on the server side to generate excel. File, and then download it by the client.
Because the Excel file is relatively slow, I am a TXT text, and then saved it as an excel file. Not much to say, first show my code.
using system;
using system.data;
using system.io;
using system.web;
namespace toexceldsns
{{
public class toexcelds
{{
Private String_txtPath; // TXT text path
Private String_XLSPATH; // Excel's path
Private dataset_ds;
Public Toexcelds (String XLSPath, String TxtPath, DataSet DS) // Constructor pass the parameter of the parameter of Excel and text path and conversion DataSett
{{
_txtPath = txtpath;
_xlspath = xlspath;
_ds = ds;
}
public void pumptoexcel () // guide excel
{{
dataarow [] DR = _ds.tables [0] .select (1 = 1);
datatable dt = _ds.tables [0];
StreamWriter SW = New StreamWriter (_TxtPath, False, System.text.encoding.Default); // Text flow
string tmp =;
FOREACH (DataColumn dc in dt.columns)
{{
tmp+= dc.caption+/t;
}
SW.Writeline (TMP+/A); // Write the first name in the dataset into the text flow and separate it with a formula
int itemcount = dt.rows.count;
int columncount = dt.columns.count;
For (int j = 2; j <2+itemcount; j ++) // Write each line in dataset into the text flow, separate the table symbols
{{
tmp =;
for (int k = 1; k <colorncount+1; k ++)
{{
tmp+= DR [J-2] [k-1] .tring ()+/t;
}
SW.Writeline (TMP+/A);
}
sw.flush ();
file.copy (_txtpath, _xlspath, true); // Save txt as Excel as Excel
sw.close ();
}
}
}
A simple and convenient guide Excel is completed. Of course, some people will mention whether there will be problems if you guide Excel. After testing, there is no problem. The reason is that there is already a local area in the guide Excel A copy, so there is no problem with conflict. I hope everyone can be inspired from it, so as to customize a more scientific method. Of course, don't forget to share it!