解决方案 »

  1.   

    最简单的方法是 用ado等数据库访问驱动 去直接读取excel的数据
    如果要复杂的控制 那只有自动化服务
    。net的msdn里面有例子 你可以搜索一下
    net开发office我没做过delphi到做过,但两者本质没多大区别
      

  2.   

    提供读取EXCEL文件的代码, 自己改一下.    '打开EXCEL按钮
        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
      

  3.   

    不是读取EXCEL文件,是没有EXCEL文件的,而是想要正确的新建一个空的EXCEL文件
      

  4.   

    不是读取EXCEL文件,是没有EXCEL文件的,而是想要正确的新建一个空的EXCEL文件
      

  5.   

    不是读取EXCEL文件,是没有EXCEL文件的,而是想要正确的新建一个空的EXCEL文件
      

  6.   

    //define
    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");
      

  7.   

    我要用代码新建一个空的EXCEL文件在一个文件夹下,这个文件夹下本来没有,忽然间就冒出一个空白的EXCEL文件
      

  8.   

    而且这个EXCEL文件里,什么数据也没有
      

  9.   

    就像用鼠标操作一样,右击 -》新建-》Microsoft Excel文件,我现在想通过代码来实现
      

  10.   

    string fileName = this.GetFileName();
    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");
      

  11.   

    就像用鼠标操作一样,右击 -》新建-》Microsoft Excel文件,我现在想通过代码来实现
    ???/我的意思是这样