日期:2014-05-18  浏览次数:20500 次

提问一个导出EXCEL问题?
SQL数据库,一个一万条数据,其中要经过一些处理后导出EXCEL文件,请问高手是以什么样的方案来实现!谢谢!

------解决方案--------------------
需要什么样的处理?
------解决方案--------------------
从数据库到出
还是c#导出
前者很简单
------解决方案--------------------
我也正好想了解导入导出Excle的问题,学习,帮顶
------解决方案--------------------
如果你的数据是以DataGrid显示的那么DataGrid已经提供了导出成Excel的方法,

如果不是,那就使用流
------解决方案--------------------
我自己写的一段导出为excel的代码,SQL语句中未处理,导出时碰到重复数据后合并行


private void ExportBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
string strFileName= " ";
System.Web.UI.WebControls.CheckBox chkExport=null;
Excel.ApplicationClass excel=null;
Excel.Workbook workbook=null;
Excel.Worksheet activeSheet=null;
Excel.Worksheet sheet=null;
strFileName= "平台和项目周总结和计划 ";
if( System.IO.File.Exists( Server.MapPath(strFileName+ ".xls ") ) )
System.IO.File.Delete( Server.MapPath(strFileName+ ".xls ") );
try
{
excel=new Excel.ApplicationClass();
workbook = excel.Workbooks.Add(Type.Missing);
activeSheet=(Excel.Worksheet)workbook.ActiveSheet;
int week=0;
int rowStart=1;
int rowCur=1;
string strItem=null;
int iItem=2;
foreach(DataGridItem oDataGridItem in dgWP.Items)
{
chkExport = (System.Web.UI.WebControls.CheckBox)oDataGridItem.FindControl( "WPCheckBox ");
if(chkExport.Checked==true)
{
string strWeek=((System.Web.UI.WebControls.Label)(oDataGridItem.FindControl( "weekLabel "))).Text;
if(week!=int.Parse(strWeek))//以周为单位分页
{
sheet = (Excel.Worksheet)excel.Sheets.Add(activeSheet,Type.Missing,Type.Missing,Type.Missing);
DateTime dt=Convert.ToDateTime(oDataGridItem.Cells[4].Text);
DateTime dtStart=(int)dt.DayOfWeek==0?dt.AddDays(1):dt.AddDays(6-(int)dt.DayOfWeek);
sheet.Name=dtStart.ToShortDateString()+ "计划 ";
FillExcelTitle(sheet);
week=int.Parse(strWeek);
rowStart=2;
rowCur=2;
}
//填写该计划的详细内容
System.Data.DataTable dtWPContent=wpContent.SelectWPContentbyWPID(oDataGridItem.Cells[1].Text).Tables[0];
if(dtWPContent.Rows.Count> 0)
{
sheet.Cells[rowCur,1]=dtWPContent.Rows[0][ "ProductLineName "].ToString();
for(int i=0;i <dtWPContent.Rows.Count;i++)
{
if(strItem==dtWPContent.Rows[i][ "ProductTypeName "].ToString())
{
sheet.get_Range( "B "+iItem.ToString(), "B "+(rowCur).ToString()).Merge(0);
sheet.get_Range( "C "+iItem.ToString(), "C "+(rowCur).ToString()).Merge(0);
}
else
{
if(strItem==null) strItem=dtWPContent.Rows[i][ "ProductTypeName "].ToString();
sheet.Cells[rowCur,2]=dtWPContent.Rows[i][ "ProductTypeName "].ToString();
sheet.Cells[rowCur,3]=dtWPContent.Rows[i][ "Frequency "].ToString();
strItem=dtWPContent.Rows[i][ "ProductTypeName "].ToString();
iItem=rowCur;
}
sheet.Cells[rowCur,4]=dtWPContent.Rows[i][ "ProductSpec "].ToString();
sheet.Cells[rowCur,5]=dtWPContent.Rows[i][ "Content "].ToString()+ " "+dtWPContent.Rows[i][ "Tester "].ToString();
if(dtWPContent.Rows[i][ "bTempFlag "].ToString()== "1 ")
{