打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
C# Excel.Application
oledb方法
using System.Data.OleDb;

            string strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\\test.xls; Extended Properties=Excel 8.0";
            OleDbConnection myConn 
= new OleDbConnection(strCon);
            
string strCom = " Select * FROM [1$A1:C100] ";
            myConn.Open();
            OleDbDataAdapter myCommand 
= new OleDbDataAdapter(strCom, myConn);
            DataSet myDataSet 
= new DataSet();
            myCommand.Fill(myDataSet, 
"1$");
            myConn.Close();
            dataGridView1.DataSource 
= myDataSet.Tables[0];
            
//MessageBox.Show(dataGridView1.ColumnCount.ToString());
            dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
            dataGridView1.Columns[
1].SortMode = DataGridViewColumnSortMode.NotSortable;
            dataGridView1.Columns[
2].SortMode = DataGridViewColumnSortMode.NotSortable;
            dataGridView1.Columns[
0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dataGridView1.Columns[
1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dataGridView1.Columns[
2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dataGridView1.ReadOnly 
= true;

Excel.Application方法
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;


            Excel.Application oXL = new Microsoft.Office.Interop.Excel.Application();
            oXL.Visible 
= true;

            Excel._Workbook oWB2
=(Excel._Workbook)oXL.Workbooks.Open(@"f:\test.xls"
                Missing.Value, 
                Missing.Value, 
                Missing.Value, 
                Missing.Value, 
                Missing.Value, 
                Missing.Value, 
                Missing.Value, 
                Missing.Value, 
                Missing.Value, 
                Missing.Value, 
                Missing.Value, 
                Missing.Value, 
                Missing.Value, 
                Missing.Value
                );

            Excel._Worksheet oSheet 
= (Excel._Worksheet)oWB.ActiveSheet;
            Excel.Shape testShape;
            Excel.Range oRng;
            testShape 
= oSheet.Shapes.AddLine(303010030);
            testShape.Line.BeginArrowheadStyle 
= Microsoft.Office.Core.MsoArrowheadStyle.msoArrowheadOval;
            testShape.Line.EndArrowheadStyle 
= Microsoft.Office.Core.MsoArrowheadStyle.msoArrowheadOpen;
            testShape.Line.Style 
= Microsoft.Office.Core.MsoLineStyle.msoLineThickBetweenThin;
            
            oWB2.SaveAs(
@"c:\1.xls"
                Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8, 
                Missing.Value, 
                Missing.Value, 
                Missing.Value, 
                Missing.Value, 
                Excel.XlSaveAsAccessMode.xlNoChange,
                Missing.Value, 
                Missing.Value, 
                Missing.Value, 
                Missing.Value, 
                Missing.Value);
            oXL.Quit();
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C#实现向已存在的Excel文件中写入数据实例(可用两种方法)
c#获取txt,word,excel文档内容方法
excel C# 报表制作汇总
【转】教你用C#读写、删除、更新excel表格记录
C#的Excel编程 - Software-as-a-Service(软件即服务) - I...
C# winform 开发之Excel操作
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服