急
解决方案 »
- OracleDataAdapter.Fill(ds,tablename) OCI-22053: 溢出错误
- 为什么绑定了listview1的tag值,但是listview1 的Tag为Null
- c# 里面 在连接数据库的时候报错 不知道是什么问题还请各位帮忙?
- 如何把控件动态定位到datagridview单元格
- 线程回调函数中弹出的对话框可以跑到主画面的背后。怎么办??
- 用c#开发OPC客户端程序怎么办?
- 如何提示用户等待
- 关于登陆控件登陆问题
- 请高手帮忙啊,搞好几天了没琢磨出来!c#读取exsl指定单元格判断是否有中文截取前一位
- 关于CefSharp的显示问题,请大神帮帮忙
- 水晶报表打包问题,高分求救
- 如何删除ini文件中指定Key及其值?
如果要复杂的控制 那只有自动化服务
。net的msdn里面有例子 你可以搜索一下
net开发office我没做过delphi到做过,但两者本质没多大区别
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim openFileDialog1 As New OpenFileDialog Dim tbl As DataTable '创建DATATABLE
openFileDialog1.InitialDirectory = "d:\"
openFileDialog1.Filter = "txt files (*.xls)|*.xls"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True If openFileDialog1.ShowDialog() = DialogResult.OK Then '打开选择文件对话框
FileName = openFileDialog1.FileName '取得文件路径
Try
Dim xlsconn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName & ";Extended Properties=Excel 8.0;")
xlsconn.Open() '打开EXCEL文件
tbl = xlsconn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"}) '将EXCEL里面所有的表名,填充到DATATABLE
Dim i As Integer Me.ListBox2.Items.Clear() '清除到LISTBOX
For i = 0 To tbl.Rows.Count - 1 '将所有的EXCEL表,填充到DATASET
'result(i) = tbl.Rows(i).Item("TABLE_NAME")
Dim xlsconn1 As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName & ";Extended Properties=Excel 8.0;")
xlsconn1.Open()
Dim mda1 As OleDb.OleDbDataAdapter
mda1 = New OleDb.OleDbDataAdapter("select * from [" & tbl.Rows(i).Item("TABLE_NAME") & "]", xlsconn)
mda1.Fill(mds2, tbl.Rows(i).Item("TABLE_NAME"))
ListBox2.Items.Add(tbl.Rows(i).Item("TABLE_NAME")) '将表名添加到LISTBOX
Me.Button5.Enabled = True
Next
Catch ex As Exception
MsgBox(ex.Source & ex.Message)
End Try
End If
End Sub
'EXCEL转ACCESS,选择EXCEL的表名
Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged
Dim tbl As DataTable Dim xlsconn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName & ";Extended Properties=Excel 8.0;") '创建EXCEL文件的连接
xlsconn.Open() '打开链接
Dim mda1 As OleDb.OleDbDataAdapter
mda1 = New OleDb.OleDbDataAdapter("select * from [" & Me.ListBox2.SelectedItem & "]", xlsconn) '查询数据
mda1.Fill(mds1, Me.ListBox2.SelectedItem) '将选择的表,填充到DATASET
DataGrid2.DataSource = mds1.Tables(Me.ListBox2.SelectedItem) '将数据绑定到DATAGRID
End Sub
Excel.ApplicationClass excelApp ;
excelApp = new Excel.ApplicationClass();
Excel.Workbook excelBook =excelApp.Workbooks.Add(1);
Excel.Worksheet excelSheet=(Excel.Worksheet)excelBook.Worksheets[1];
//就可以看到了,新建了一个空excel
excelApp.Visible=true;
//set head text
excelSheet.Cells[1,1]="UserId";
excelSheet.Cells[1,2]="UserName";
excelSheet.Cells[1,3]="UserSalary";
//write info into the excel
for(int i=1;i < grid_serch.VisibleRowCount;i++)
{
excelSheet.Cells[i+1,1]=grid_serch[i-1,0].ToString();
excelSheet.Cells[i+1,2]=grid_serch[i-1,1];
excelSheet.Cells[i+1,3]=grid_serch[i-1,2];
}
//save as
save_excel();
Stream stream =null;
SaveFileDialog sfd = new SaveFileDialog();
sfd.DefaultExt=".xls";
sfd.Filter="*.xls|*.xls";
if (sfd.ShowDialog()==DialogResult.OK)
{
if((stream=sfd.OpenFile())!=null)
{
stream.Close(); }
excelApp.ActiveWorkbook.SaveCopyAs(sfd.FileName);
}
//print
excelSheet.PrintOut(1,1,1,true,"Dell Laser Printer 1700n",false,false,@"d:\print.xls");
if(fileName =="") return; Excel.Application app = new Excel.Application();
if (app == null)
{
CErrorService.ProcessError("Excel启动失败!");
}
app.Visible = false;
Workbooks workbooks = app.Workbooks;
_Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Worksheet worksheet = (Worksheet)workbook.Sheets.get_Item(1);
if (worksheet == null)
{
CErrorService.ProcessError("工作表获得失败!");
}
try
{
workbook.SaveCopyAs(fileName);
workbook.Saved = true;
app.UserControl = false;
app.UserControl = false;
app.Quit();
app.Quit();
}
catch (COMException)
{
Console.WriteLine ("User closed Excel manually, so we don't have to do that");
}
this.KillProcess("EXCEL");
???/我的意思是这样