1、要制作一个word(excel)模板,固定内容输入后,标签如何设置?
2、想通过IE打开,如何把数据库中的数据添加到模板的相应位置?
16 个解决方案
#1
帮你顶
#2
给你推荐一本好书:
《Visual Studio的 Office 工具_通过C#编程Excel 、Word以及InfoPath》
你从网络上搜索一下,可以下载的,里面有你的解决方法!
《Visual Studio的 Office 工具_通过C#编程Excel 、Word以及InfoPath》
你从网络上搜索一下,可以下载的,里面有你的解决方法!
#3
要不你留下一个电子邮件,我给你发过去!共12M
#4
好的,谢谢!
wulongtianzi@163.com
wulongtianzi@163.com
#5
麻烦楼上给我也发一份,谢谢!!!
cdzhou@126.com
cdzhou@126.com
#6
wulongtianzi (乌龙) 已经发给你了,查收一下!
#7
已收到,谢谢!有没有中文版的阿?
#8
你好,可以给我一份么?谢谢!
ping@mail.dhu.edu.cn
ping@mail.dhu.edu.cn
#9
你好,我也想要一份,谢谢你
我的信箱是:
wenshuai128@163.com
我刚开始学.net,希望你多多指教
我的信箱是:
wenshuai128@163.com
我刚开始学.net,希望你多多指教
#10
请问可以给我一份吗?谢谢
yunnan201@tom.com
yunnan201@tom.com
#11
我给 你一段代码,可以利用要制作一个excel模板,固定内容以后,把数据库中的数据添加到模板的相应位置
首先引用一个Mircosoft e Excel oobject Libray
/// <summary>
/// 杀进程的函数
/// </summary>
/// <param name="processName"></param>
public static void KillProcess( string processName )
{
System.Diagnostics.Process myproc= new System.Diagnostics.Process();
//得到所有打开的进程
try
{
foreach (System.Diagnostics.Process thisproc in System.Diagnostics.Process.GetProcessesByName(processName))
{
if(!thisproc.CloseMainWindow())
{
thisproc.Kill();
thisproc.Close();
}
}
}
catch(Exception Exc)
{
}
}
/// <summary>
/// 数据导入到EXCEL里面
/// </summary>
public void WriteToEecelByO(string strDataTime,string strHour,bool flag)
{
//定义操作EXCEL的一系列的东西
Excel.Application oExcel=new Excel.ApplicationClass();
Excel.Workbooks oBooks;
Excel.Workbook oBook;
Excel.Sheets oSheets;
Excel.Worksheet oSheet;
Excel.Range oCells ;
sFile = Server.MapPath(null)+@"\excel\Reports"+this.returnFileName(strDataTime)+".xls";
//定义模版文件
sTemplate = Server.MapPath(null)+@"\District_all.xls";
oExcel.Visible = false;
oExcel.DisplayAlerts = false;
//定义一个新的工作簿
oBooks =(Excel.Workbooks)oExcel.Workbooks;
//oBooks.Open (sTemplate,null,null,Excel.XlFileFormat.xlExcel4,null,null,null,null,null,null,null,null,null,null,null);
oBook = (Excel.Workbook)oBooks.Add(sTemplate);
oSheets =(Excel.Sheets)oBook.Worksheets;
oSheet = (Excel.Worksheet)oSheets.get_Item(1);
//命名该sheet
oSheet.Name = "First Sheet";
oCells = oSheet.Cells;
//调用dumpdata过程,将数据导入到Excel中去
//数据取出来放在dt里面
DumpData(dt, oCells);
//保存
oSheet.SaveAs(sFile,Excel.XlFileFormat.xlExcel4,null,null,null,null,null,null,null,null);
oBook.Close(null,null,null);
oExcel.Quit();
//关闭所有的进程,释放资源
//关闭所有的进程,释放资源
System.Runtime.InteropServices.Marshal.ReleaseComObject(oCells);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheets);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject((object)oExcel);
oCells=null;
oExcel = null;
oBook = null;
oSheet = null;
oBooks = null;
oSheets = null;
oExcel=null;
// //垃圾回收
System.GC.Collect();
System.GC.Collect();
System.GC.Collect();
KillProcess("EXCEL");
}
/// <summary>
/// 往Excel里面添加数据
/// </summary>
/// <param name="dt"></param>
/// <param name="oCells"></param>
public void DumpData(DataTable dt , Excel.Range oCells )
{
DataRow dr;
object[] ary;
int iRow=0;
int iCol=0;
for(iRow=0;iRow<dt.Rows.Count;iRow++)
{
dr=dt.Rows[iRow];
ary=dr.ItemArray;
for (iCol=0; iCol<ary.Length;iCol++)
{
oCells[iRow +从第几行开始, iCol + 从第几列来始] = ary[iCol].ToString();
this.Response.Write(ary[iCol].ToString());
}
}
}
首先引用一个Mircosoft e Excel oobject Libray
/// <summary>
/// 杀进程的函数
/// </summary>
/// <param name="processName"></param>
public static void KillProcess( string processName )
{
System.Diagnostics.Process myproc= new System.Diagnostics.Process();
//得到所有打开的进程
try
{
foreach (System.Diagnostics.Process thisproc in System.Diagnostics.Process.GetProcessesByName(processName))
{
if(!thisproc.CloseMainWindow())
{
thisproc.Kill();
thisproc.Close();
}
}
}
catch(Exception Exc)
{
}
}
/// <summary>
/// 数据导入到EXCEL里面
/// </summary>
public void WriteToEecelByO(string strDataTime,string strHour,bool flag)
{
//定义操作EXCEL的一系列的东西
Excel.Application oExcel=new Excel.ApplicationClass();
Excel.Workbooks oBooks;
Excel.Workbook oBook;
Excel.Sheets oSheets;
Excel.Worksheet oSheet;
Excel.Range oCells ;
sFile = Server.MapPath(null)+@"\excel\Reports"+this.returnFileName(strDataTime)+".xls";
//定义模版文件
sTemplate = Server.MapPath(null)+@"\District_all.xls";
oExcel.Visible = false;
oExcel.DisplayAlerts = false;
//定义一个新的工作簿
oBooks =(Excel.Workbooks)oExcel.Workbooks;
//oBooks.Open (sTemplate,null,null,Excel.XlFileFormat.xlExcel4,null,null,null,null,null,null,null,null,null,null,null);
oBook = (Excel.Workbook)oBooks.Add(sTemplate);
oSheets =(Excel.Sheets)oBook.Worksheets;
oSheet = (Excel.Worksheet)oSheets.get_Item(1);
//命名该sheet
oSheet.Name = "First Sheet";
oCells = oSheet.Cells;
//调用dumpdata过程,将数据导入到Excel中去
//数据取出来放在dt里面
DumpData(dt, oCells);
//保存
oSheet.SaveAs(sFile,Excel.XlFileFormat.xlExcel4,null,null,null,null,null,null,null,null);
oBook.Close(null,null,null);
oExcel.Quit();
//关闭所有的进程,释放资源
//关闭所有的进程,释放资源
System.Runtime.InteropServices.Marshal.ReleaseComObject(oCells);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheets);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject((object)oExcel);
oCells=null;
oExcel = null;
oBook = null;
oSheet = null;
oBooks = null;
oSheets = null;
oExcel=null;
// //垃圾回收
System.GC.Collect();
System.GC.Collect();
System.GC.Collect();
KillProcess("EXCEL");
}
/// <summary>
/// 往Excel里面添加数据
/// </summary>
/// <param name="dt"></param>
/// <param name="oCells"></param>
public void DumpData(DataTable dt , Excel.Range oCells )
{
DataRow dr;
object[] ary;
int iRow=0;
int iCol=0;
for(iRow=0;iRow<dt.Rows.Count;iRow++)
{
dr=dt.Rows[iRow];
ary=dr.ItemArray;
for (iCol=0; iCol<ary.Length;iCol++)
{
oCells[iRow +从第几行开始, iCol + 从第几列来始] = ary[iCol].ToString();
this.Response.Write(ary[iCol].ToString());
}
}
}
#12
补充一点,要添加
using System.Reflection;
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;的引用
using System.Reflection;
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;的引用
#13
我也问了一贴:
http://community.csdn.net/Expert/topic/4578/4578425.xml?temp=.494137
morality看看
http://community.csdn.net/Expert/topic/4578/4578425.xml?temp=.494137
morality看看
#14
Dreamweaver如何引用?
#15
Exception Details: System.Web.HttpException: Could not create an object of type 'Microsoft.Office.Interop.Excel.Application'.
#16
用freetextbox编辑后存入数据库,取出来显示就是有格式的
#1
帮你顶
#2
给你推荐一本好书:
《Visual Studio的 Office 工具_通过C#编程Excel 、Word以及InfoPath》
你从网络上搜索一下,可以下载的,里面有你的解决方法!
《Visual Studio的 Office 工具_通过C#编程Excel 、Word以及InfoPath》
你从网络上搜索一下,可以下载的,里面有你的解决方法!
#3
要不你留下一个电子邮件,我给你发过去!共12M
#4
好的,谢谢!
wulongtianzi@163.com
wulongtianzi@163.com
#5
麻烦楼上给我也发一份,谢谢!!!
cdzhou@126.com
cdzhou@126.com
#6
wulongtianzi (乌龙) 已经发给你了,查收一下!
#7
已收到,谢谢!有没有中文版的阿?
#8
你好,可以给我一份么?谢谢!
ping@mail.dhu.edu.cn
ping@mail.dhu.edu.cn
#9
你好,我也想要一份,谢谢你
我的信箱是:
wenshuai128@163.com
我刚开始学.net,希望你多多指教
我的信箱是:
wenshuai128@163.com
我刚开始学.net,希望你多多指教
#10
请问可以给我一份吗?谢谢
yunnan201@tom.com
yunnan201@tom.com
#11
我给 你一段代码,可以利用要制作一个excel模板,固定内容以后,把数据库中的数据添加到模板的相应位置
首先引用一个Mircosoft e Excel oobject Libray
/// <summary>
/// 杀进程的函数
/// </summary>
/// <param name="processName"></param>
public static void KillProcess( string processName )
{
System.Diagnostics.Process myproc= new System.Diagnostics.Process();
//得到所有打开的进程
try
{
foreach (System.Diagnostics.Process thisproc in System.Diagnostics.Process.GetProcessesByName(processName))
{
if(!thisproc.CloseMainWindow())
{
thisproc.Kill();
thisproc.Close();
}
}
}
catch(Exception Exc)
{
}
}
/// <summary>
/// 数据导入到EXCEL里面
/// </summary>
public void WriteToEecelByO(string strDataTime,string strHour,bool flag)
{
//定义操作EXCEL的一系列的东西
Excel.Application oExcel=new Excel.ApplicationClass();
Excel.Workbooks oBooks;
Excel.Workbook oBook;
Excel.Sheets oSheets;
Excel.Worksheet oSheet;
Excel.Range oCells ;
sFile = Server.MapPath(null)+@"\excel\Reports"+this.returnFileName(strDataTime)+".xls";
//定义模版文件
sTemplate = Server.MapPath(null)+@"\District_all.xls";
oExcel.Visible = false;
oExcel.DisplayAlerts = false;
//定义一个新的工作簿
oBooks =(Excel.Workbooks)oExcel.Workbooks;
//oBooks.Open (sTemplate,null,null,Excel.XlFileFormat.xlExcel4,null,null,null,null,null,null,null,null,null,null,null);
oBook = (Excel.Workbook)oBooks.Add(sTemplate);
oSheets =(Excel.Sheets)oBook.Worksheets;
oSheet = (Excel.Worksheet)oSheets.get_Item(1);
//命名该sheet
oSheet.Name = "First Sheet";
oCells = oSheet.Cells;
//调用dumpdata过程,将数据导入到Excel中去
//数据取出来放在dt里面
DumpData(dt, oCells);
//保存
oSheet.SaveAs(sFile,Excel.XlFileFormat.xlExcel4,null,null,null,null,null,null,null,null);
oBook.Close(null,null,null);
oExcel.Quit();
//关闭所有的进程,释放资源
//关闭所有的进程,释放资源
System.Runtime.InteropServices.Marshal.ReleaseComObject(oCells);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheets);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject((object)oExcel);
oCells=null;
oExcel = null;
oBook = null;
oSheet = null;
oBooks = null;
oSheets = null;
oExcel=null;
// //垃圾回收
System.GC.Collect();
System.GC.Collect();
System.GC.Collect();
KillProcess("EXCEL");
}
/// <summary>
/// 往Excel里面添加数据
/// </summary>
/// <param name="dt"></param>
/// <param name="oCells"></param>
public void DumpData(DataTable dt , Excel.Range oCells )
{
DataRow dr;
object[] ary;
int iRow=0;
int iCol=0;
for(iRow=0;iRow<dt.Rows.Count;iRow++)
{
dr=dt.Rows[iRow];
ary=dr.ItemArray;
for (iCol=0; iCol<ary.Length;iCol++)
{
oCells[iRow +从第几行开始, iCol + 从第几列来始] = ary[iCol].ToString();
this.Response.Write(ary[iCol].ToString());
}
}
}
首先引用一个Mircosoft e Excel oobject Libray
/// <summary>
/// 杀进程的函数
/// </summary>
/// <param name="processName"></param>
public static void KillProcess( string processName )
{
System.Diagnostics.Process myproc= new System.Diagnostics.Process();
//得到所有打开的进程
try
{
foreach (System.Diagnostics.Process thisproc in System.Diagnostics.Process.GetProcessesByName(processName))
{
if(!thisproc.CloseMainWindow())
{
thisproc.Kill();
thisproc.Close();
}
}
}
catch(Exception Exc)
{
}
}
/// <summary>
/// 数据导入到EXCEL里面
/// </summary>
public void WriteToEecelByO(string strDataTime,string strHour,bool flag)
{
//定义操作EXCEL的一系列的东西
Excel.Application oExcel=new Excel.ApplicationClass();
Excel.Workbooks oBooks;
Excel.Workbook oBook;
Excel.Sheets oSheets;
Excel.Worksheet oSheet;
Excel.Range oCells ;
sFile = Server.MapPath(null)+@"\excel\Reports"+this.returnFileName(strDataTime)+".xls";
//定义模版文件
sTemplate = Server.MapPath(null)+@"\District_all.xls";
oExcel.Visible = false;
oExcel.DisplayAlerts = false;
//定义一个新的工作簿
oBooks =(Excel.Workbooks)oExcel.Workbooks;
//oBooks.Open (sTemplate,null,null,Excel.XlFileFormat.xlExcel4,null,null,null,null,null,null,null,null,null,null,null);
oBook = (Excel.Workbook)oBooks.Add(sTemplate);
oSheets =(Excel.Sheets)oBook.Worksheets;
oSheet = (Excel.Worksheet)oSheets.get_Item(1);
//命名该sheet
oSheet.Name = "First Sheet";
oCells = oSheet.Cells;
//调用dumpdata过程,将数据导入到Excel中去
//数据取出来放在dt里面
DumpData(dt, oCells);
//保存
oSheet.SaveAs(sFile,Excel.XlFileFormat.xlExcel4,null,null,null,null,null,null,null,null);
oBook.Close(null,null,null);
oExcel.Quit();
//关闭所有的进程,释放资源
//关闭所有的进程,释放资源
System.Runtime.InteropServices.Marshal.ReleaseComObject(oCells);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheets);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject((object)oExcel);
oCells=null;
oExcel = null;
oBook = null;
oSheet = null;
oBooks = null;
oSheets = null;
oExcel=null;
// //垃圾回收
System.GC.Collect();
System.GC.Collect();
System.GC.Collect();
KillProcess("EXCEL");
}
/// <summary>
/// 往Excel里面添加数据
/// </summary>
/// <param name="dt"></param>
/// <param name="oCells"></param>
public void DumpData(DataTable dt , Excel.Range oCells )
{
DataRow dr;
object[] ary;
int iRow=0;
int iCol=0;
for(iRow=0;iRow<dt.Rows.Count;iRow++)
{
dr=dt.Rows[iRow];
ary=dr.ItemArray;
for (iCol=0; iCol<ary.Length;iCol++)
{
oCells[iRow +从第几行开始, iCol + 从第几列来始] = ary[iCol].ToString();
this.Response.Write(ary[iCol].ToString());
}
}
}
#12
补充一点,要添加
using System.Reflection;
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;的引用
using System.Reflection;
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;的引用
#13
我也问了一贴:
http://community.csdn.net/Expert/topic/4578/4578425.xml?temp=.494137
morality看看
http://community.csdn.net/Expert/topic/4578/4578425.xml?temp=.494137
morality看看
#14
Dreamweaver如何引用?
#15
Exception Details: System.Web.HttpException: Could not create an object of type 'Microsoft.Office.Interop.Excel.Application'.
#16
用freetextbox编辑后存入数据库,取出来显示就是有格式的