有这样一个功能,是否可以实现 我发现把HTML文件另存为.xls文件之后,用EXCEL打开,然后在EXCEL里做任意修改保存后,它就不是之前的HTML了,源文件立刻变成EXCEL的了。所以我就想,能不能模拟一个用EXCEL打开一个HTML文件,然后修改、保存的功能? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 读取HTML内容,导出建立Excel文件, 那你为什么非要用Excel来编码HTML呢? protected void ExportExcel() { gridbind(); if(ds1==null) return; string saveFileName="";// bool fileSaved=false; SaveFileDialog saveDialog=new SaveFileDialog(); saveDialog.DefaultExt ="xls"; saveDialog.Filter="Excel文件|*.xls"; saveDialog.FileName ="Sheet1"; saveDialog.ShowDialog(); saveFileName=saveDialog.FileName; if(saveFileName.IndexOf(":")<0) return; //被点了取消// excelapp.Workbooks.Open (App.path & 工程进度表.xls) Excel.Application xlApp=new Excel.Application(); object missing=System.Reflection.Missing.Value; if(xlApp==null) { MessageBox.Show("无法创建Excel对象,可能您的机子未安装Excel"); return; } Excel.Workbooks workbooks=xlApp.Workbooks; Excel.Workbook workbook=workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet); Excel.Worksheet worksheet=(Excel.Worksheet)workbook.Worksheets[1];//取得sheet1 Excel.Range range; string oldCaption=Title_label .Text.Trim (); long totalCount=ds1.Tables[0].Rows.Count; long rowRead=0; float percent=0; worksheet.Cells[1,1]=Title_label .Text.Trim (); //写入字段 for(int i=0;i { worksheet.Cells[2,i+1]=ds1.Tables[0].Columns.ColumnName; range=(Excel.Range)worksheet.Cells[2,i+1]; range.Interior.ColorIndex = 15; range.Font.Bold = true; } //写入数值 Caption .Visible = true; for(int r=0;r { for(int i=0;i { worksheet.Cells[r+3,i+1]=ds1.Tables[0].Rows[r]; } rowRead++; percent=((float)(100*rowRead))/totalCount; this.Caption.Text= "正在导出数据["+ percent.ToString("0.00") +"%]..."; Application.DoEvents(); } worksheet.SaveAs(saveFileName,missing,missing,missing,missing,missing,missing,missing,missing); this.Caption.Visible= false; this.Caption.Text= oldCaption; range=worksheet.get_Range(worksheet.Cells[2,1],worksheet.Cells[ds1.Tables[0].Rows.Count+2,ds1.Tables[0].Columns.Count]); range.BorderAround(Excel.XlLineStyle.xlContinuous,Excel.XlBorderWeight.xlThin,Excel.XlColorIndex.xlColorIndexAutomatic,null); range.Borders[Excel.XlBordersIndex.xlInsideHorizontal].ColorIndex = Excel.XlColorIndex.xlColorIndexAutomatic; range.Borders[Excel.XlBordersIndex.xlInsideHorizontal].LineStyle =Excel.XlLineStyle.xlContinuous; range.Borders[Excel.XlBordersIndex.xlInsideHorizontal].Weight =Excel.XlBorderWeight.xlThin; if(ds1.Tables[0].Columns.Count>1) { range.Borders[Excel.XlBordersIndex.xlInsideVertical].ColorIndex=Excel.XlColorIndex.xlColorIndexAutomatic; } workbook.Close(missing,missing,missing); xlApp.Quit(); } 你说的是自己读写EXCEL,我是说模拟打开HTML--修改(随便改一下就行)--保存这样的一个操作 你说的这个貌似是DataTable导出到EXCEL,和我的完全不同,我的是纯HTML,就是table tr td,明白? 如果你是要把HTML里面的表格保存成EXECL文件的话可以把这段HTML作为XML对象来操作,然后一个节点一个节点的读,在一个CELL一个CELL得写进表格里 面试回来,答题不会 不规则xml操作 谁能给一个.NET的WIN32 API包装类呢?内容全一点的。 多线程下产生无重复随机数 c#将网络上的图片读成字节流 如何在MDI的子窗口中定位光标所在位置 用.NET的同胞们,你们谁用reporting services做过图表,能否提供一些参考代码 关于BackgroundWorker占用线程问题 Win8的管理员启动 请教!----读取xml发生错误!---- 关于一个Microsoft .NET Framework SDK v2.0安装问题 webbrowser.document为空?
protected void ExportExcel()
{
gridbind();
if(ds1==null) return;
string saveFileName="";
// bool fileSaved=false;
SaveFileDialog saveDialog=new SaveFileDialog();
saveDialog.DefaultExt ="xls";
saveDialog.Filter="Excel文件|*.xls";
saveDialog.FileName ="Sheet1";
saveDialog.ShowDialog();
saveFileName=saveDialog.FileName;
if(saveFileName.IndexOf(":")<0) return; //被点了取消
// excelapp.Workbooks.Open (App.path & 工程进度表.xls)
Excel.Application xlApp=new Excel.Application();
object missing=System.Reflection.Missing.Value;
if(xlApp==null)
{
MessageBox.Show("无法创建Excel对象,可能您的机子未安装Excel");
return;
}
Excel.Workbooks workbooks=xlApp.Workbooks;
Excel.Workbook workbook=workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
Excel.Worksheet worksheet=(Excel.Worksheet)workbook.Worksheets[1];//取得sheet1
Excel.Range range;
string oldCaption=Title_label .Text.Trim ();
long totalCount=ds1.Tables[0].Rows.Count;
long rowRead=0;
float percent=0;
worksheet.Cells[1,1]=Title_label .Text.Trim ();
//写入字段
for(int i=0;i {
worksheet.Cells[2,i+1]=ds1.Tables[0].Columns.ColumnName;
range=(Excel.Range)worksheet.Cells[2,i+1];
range.Interior.ColorIndex = 15;
range.Font.Bold = true;
}
//写入数值
Caption .Visible = true;
for(int r=0;r {
for(int i=0;i {
worksheet.Cells[r+3,i+1]=ds1.Tables[0].Rows[r];
}
rowRead++;
percent=((float)(100*rowRead))/totalCount;
this.Caption.Text= "正在导出数据["+ percent.ToString("0.00") +"%]...";
Application.DoEvents();
}
worksheet.SaveAs(saveFileName,missing,missing,missing,missing,missing,missing,missing,missing);
this.Caption.Visible= false;
this.Caption.Text= oldCaption;
range=worksheet.get_Range(worksheet.Cells[2,1],worksheet.Cells[ds1.Tables[0].Rows.Count+2,ds1.Tables[0].Columns.Count]);
range.BorderAround(Excel.XlLineStyle.xlContinuous,Excel.XlBorderWeight.xlThin,Excel.XlColorIndex.xlColorIndexAutomatic,null);
range.Borders[Excel.XlBordersIndex.xlInsideHorizontal].ColorIndex = Excel.XlColorIndex.xlColorIndexAutomatic;
range.Borders[Excel.XlBordersIndex.xlInsideHorizontal].LineStyle =Excel.XlLineStyle.xlContinuous;
range.Borders[Excel.XlBordersIndex.xlInsideHorizontal].Weight =Excel.XlBorderWeight.xlThin;
if(ds1.Tables[0].Columns.Count>1)
{
range.Borders[Excel.XlBordersIndex.xlInsideVertical].ColorIndex=Excel.XlColorIndex.xlColorIndexAutomatic;
}
workbook.Close(missing,missing,missing);
xlApp.Quit();
}
你说的是自己读写EXCEL,我是说模拟打开HTML--修改(随便改一下就行)--保存这样的一个操作
你说的这个貌似是DataTable导出到EXCEL,和我的完全不同,我的是纯HTML,就是table tr td,明白?