乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > c#的form中如何<em>嵌入excel</em>-winform 嵌入excel,dsofr

c#的form中如何<em>嵌入excel</em>-winform 嵌入excel,dsofr

作者:乔山办公网日期:

返回目录:excel表格制作


这个可以吗 ?
我有看到过类似的控件有这个功能, 不过是收费的,好像叫flex cell,具体记不太清楚,大概是这个样子.
真希望EXCEL能嵌入到WINFORM中,哈哈.

OleDbConnection con = new OleDbConnection();
try
{
OpenFileDialog openFile = new OpenFileDialog();//打开文件对话框。
openFile.Filter = ("所有文件(*.*)|*.*|Excel 文件(*.xls)|*.xls|Excel 文件(*.xlsx)|*.xlsx");//后缀名。
//openFile.Filter = ("Excel 文件(*.xls)|*.xls");//后缀名。
if (openFile.ShowDialog() == DialogResult.OK)
{
string filename = openFile.FileName;
int index = filename.LastIndexOf("//");//截取文件的名字
filename = filename.Substring(index + 1);
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source=test.accdb;";
//将excel导入access
//distinct :删除excel重复的行.
//[excel名].[sheet名] 已有的excel的表e5a48de588b6e799bee5baa6e997aee7ad94364要加$
//where not in : 插入不重复的记录。

string sql = "insert into 学生表 select distinct * from [Excel 8.0;database=" +
filename + "].[Sheet1$] where ID not in (select ID from 学生表) ";
string sql1 = "delete from 学生表";
OleDbCommand com1 = new OleDbCommand(sql1, con);
OleDbCommand com = new OleDbCommand(sql, con);
con.Open();
com1.ExecuteNonQuery();
com.ExecuteNonQuery();

MessageBox.Show("导入数据成功", "导入数据", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
你可以先用循环的方法来获得改datagrid中“性别”的值,接着自己定义个变量来存放这个“性别”的1或者0,然后根据这个值用条件来判断是显示“男性”还是女性,打个比方(有五列十行数据,比方第二列显示出“性别”):
Dim intRow As Integer
Dim intColumn As Integer
Dim Gender As Integer

For intRow = 0 To 9(DataGrid的行总和)

Gender = CInt(datagrid1.Item (intRow, 1).ToString )
If Gender = 0 Then
datagrid1.Item (intRow, 1)="男"
Else
datagrid1.Item (intRow, 1)="女"
Next
请采纳答案,支持我一下。

你是要从excel中导入e79fa5e98193e59b9ee7ad94333数据到winform吗?如果是这样,可以这样:引用office11.0组件后, Microsoft.Office.Interop.Excel.Application application; //这是一个客户端
Microsoft.Office.Interop.Excel.Workbooks workbooks; //所有工作薄
Microsoft.Office.Interop.Excel.Worksheet worksheet;//工作表
Microsoft.Office.Interop.Excel.Workbook workbook; //所用到的工作表 void IsRunEX(){ OpenFileDialog openfilediaglog = new OpenFileDialog();
openfilediaglog.Filter = "xls文件|*.xls";
if (openfilediaglog.ShowDialog() == DialogResult.OK)
{
FieldName = openfilediaglog.FileName;
application = new Microsoft.Office.Interop.Excel.Application();
workbooks = application.Workbooks;
workbook = returnworkbook(FieldName, workbooks);
worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets[1]; //选择第一个表

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网