日期:2014-05-17 浏览次数:20489 次
public static void ExportExcel(string TemplatePath, Hashtable hashtable)
{
string strFileName = HttpContext.Current.Server.MapPath(TemplatePath);
beforeTime = DateTime.Now;
Object oMissing = System.Reflection.Missing.Value;
Excel.Application ex = new Excel.Application();
ex.DisplayAlerts = false;
ex.ScreenUpdating = false;
ex.Workbooks.Open(strFileName, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
Excel.Workbook workbook = ex.Application.ActiveWorkbook;
Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Sheets[1]; //from 1 not 0
foreach (object key in hashtable.Keys)
{
if (hashtable[key].GetType() == typeof(DataTable))
{
DataTable dataTable = (DataTable)hashtable[key];
int nRowCount = dataTable.Rows.Count;
int nColumnCount = dataTable.Columns.Count;
#region 如果超過2000行 將截斷DataTable
if (nRowCount > 2000)
{
for (int rowIndex = 0; rowIndex < dataTable.Rows.Count; rowIndex++)
{
if (rowIndex > 2000)
&nb