把word 的内容读出来,显示在网页上。
读execl的代码请不要是网上流行的读第一列的数据的。
老大!!
  给代码好吗?

解决方案 »

  1.   

    操作excel和access好象没多大不同。<%@Import NameSpace="System.Data"%>
    <%@Import NameSpace="System.Data.oledb"%>
    <script language=vb runat=server>
    sub page_load
    dim strsql, strconn as string
    strsql = "SELECT * FROM employee"
    strconn = "Provider=Microsoft.JET.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & Server.mappath("book2.xls")

    dim objconn as new oledbconnection(strconn)
    dim objcomm as new oledbcommand(strsql, objconn)
    try
    objconn.open
    dgd.datasource= objcomm.executereader()
    dgd.databind()
    catch
    end try
    end sub
    </script>
    <asp:datagrid id=dgd runat=server />
    book2.xls来源于sql server2000的pub数据库。
      

  2.   

    我这里有一段代码,是操作execl文档的.<%@ Page Language="VB" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.Oledb" %>
    <script language="VB" runat="server">
    Sub Page_Load(sender As Object, e As EventArgs)
    Dim myDataset As New DataSet()
    Dim myOleDbConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=c:\2.xls;" & _
    "Extended Properties=""Excel 8.0;""")
    Dim myOleDbCommand As OleDbCommand = New OleDbCommand("SELECT * FROM [Sheet1$]",myOleDbConnection)
    Dim myData As OledbDataAdapter= New OledbDataAdapter(myOleDbCommand)myData.Fill(myDataset)DataGrid1.DataSource = myDataset.Tables(0).DefaultView
    DataGrid1.DataBind()
    End Sub
    </script><html>
    <head></head>
    <body>
    <asp:Label id="L1" runat="server">读取C盘根目录下的test.xls文件,并以DataGrid的形式显示出来</asp:label>
    <asp:DataGrid id=DataGrid1 runat="server"/>
    </body>
    </html>
      

  3.   

    Namespace System.Data.OleDb 
    Public Class ExcelDG 
    Inherits System.Web.UI.Page 
    Protected WithEvents ExcelGrid As System.Web.UI.WebControls.DataGrid Public Sub page_load(ByVal sender As Object, ByVal e As EventArgs) 
    Dim connstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Inetpub\wwwroot\VOffice\Data\MayRR.xls;Extended Properties=Excel 8.0;" 
    Dim objConn As New OleDbConnection(connstr) 'use $ sign when referencing the sheet in workbook 
    Dim objadap As New OleDbDataAdapter("SELECT * FROM [agency_resid_auth$]", objConn) 
    Dim ds As New DataSet() objConn.Open() 
    'MayRR is excel workbook name 
    objadap.Fill(ds, "MayRR") 
    ExcelGrid.DataSource = ds.Tables(0).DefaultView 
    ExcelGrid.DataBind() 
    objConn.Close() 
    End Sub 
    #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. 
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 
    'CODEGEN: This method call is required by the Web Form Designer 
    'Do not modify it using the code editor. 
    InitializeComponent() 
    End Sub #End Region End Class 
    End Namespace 
      

  4.   

    看来100分不够了。
    大哥们,help!
      

  5.   

    我回来了。
    因为我自己搞定了。
    可以读出显示,存为网页,建立word文档,写入内容。
    要得留邮箱。
      

  6.   

    loveangela(非留不可) :非发布可呦!呵呵!      [email protected]
      

  7.   

    [email protected]
    谢谢
    如果excel是不规则文件,比如有些合并单元,怎么办?
      

  8.   

    [email protected]
    大哥等人发过来啊
      

  9.   

    [email protected]
    急切盼望回复
      

  10.   

    [email protected]有对Word的操作吗
    对于不规则的excel的操作,我是能实现的,一个是代码的问题,还有一个是要在服务器上配置一下,不然不代码没有权限访问excel
      

  11.   

    可以通过这样一种方法,就是先在服务器上运算,完成后马上压入web页中.这样在客户端显示。
      

  12.   

    loveangela(非留不可) 你为什么也不在这里公布出来?发邮件不累吗?
      

  13.   

    有什么好的解决方法?
    [email protected]
      

  14.   

    [email protected]
    谢谢!!!一定要发啊
      

  15.   

    你们对excel的操作都不行,如果不规则表如何办呢。
    不规则表结构也就算了,
    如果列里的数据类型不一样,我看你们怎办呢
      

  16.   

    greystar(greystar) 老兄你也太狂了一点吧,难道我随便给你一个表你也能把它读出来吗??还有类型不一样到不是什么问题
      

  17.   

    //CCWordApp.cs  word /excel 9.0 object library
    using System;
    using System.ComponentModel;
    using System.IO;
    namespace WordApplication
    {
    public class CCWordApp 
    {
    private Word.ApplicationClass oWordApplic; // a reference to Word application
    private Word.Document oDoc; // a reference to the document


    public CCWordApp()
    {
    // activate the interface with the COM object of Microsoft Word
    oWordApplic = new Word.ApplicationClass();
    } // Open a file (the file must exists) and activate it
    public void Open( string strFileName)
    {
    object fileName = strFileName;
    object readOnly = false;
    object isVisible = true;
    object missing = System.Reflection.Missing.Value; oDoc = oWordApplic.Documents.Open(ref fileName, ref missing,ref readOnly, 
    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, 
    ref missing, ref missing, ref isVisible); oDoc.Activate();
    }
    // Open a new document
    public void Open( )
    {
    object missing = System.Reflection.Missing.Value;
    oDoc = oWordApplic.Documents.Add(ref missing, ref missing,ref missing, ref missing); oDoc.Activate();
    }
    public void Quit( )
    {
    object missing = System.Reflection.Missing.Value;

    oDoc.Close(ref missing,ref missing,ref missing);

    oWordApplic.Application.Quit(ref missing, ref missing, ref missing);

    } public void Save( )
    {
    oDoc.Save();
    }
    public void SaveAs(string strFileName )
    {
    object missing = System.Reflection.Missing.Value;
    object fileName = strFileName; oDoc.SaveAs(ref fileName, ref missing,ref missing, ref missing,ref missing,ref missing,ref missing,
    ref missing,ref missing,ref missing, ref missing);
    } // Save the document in HTML format
    public void SaveAsHtml(string strFileName )
    {
    object missing = System.Reflection.Missing.Value;
    object fileName = strFileName;
    object Format = (int)Word.WdSaveFormat.wdFormatHTML;
    oDoc.SaveAs(ref fileName, ref Format,ref missing, ref missing,ref missing,ref missing,ref missing,
    ref missing,ref missing,ref missing, ref missing);
    } public void InsertText( string strText)
    {
    oWordApplic.Selection.TypeText(strText);
    } public void InsertLineBreak( )
    {
    oWordApplic.Selection.TypeParagraph();
    }
    public void InsertLineBreak( int nline)
    {
    for (int i=0; i<nline; i++)
    oWordApplic.Selection.TypeParagraph();
    } // Change the paragraph alignement
    public void SetAlignment(string strType )
    {
    switch (strType)
    {
    case "Center" :
    oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
    break;
    case "Left" :
    oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
    break;
    case "Right" :
    oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
    break;
    case "Justify" :
    oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify;
    break;
    }

    }
      

  18.   

    接上:
    public void SetFont( string strType )
    {
    switch (strType)
    {
    case "Bold":
    oWordApplic.Selection.Font.Bold = 1;
    break;
    case "Italic":
    oWordApplic.Selection.Font.Italic = 1;
    break;
    case "Underlined":
    oWordApplic.Selection.Font.Subscript = 0;
    break;
    }

    }

    // disable all the style 
    public void SetFont( )
    {
    oWordApplic.Selection.Font.Bold = 0;
    oWordApplic.Selection.Font.Italic = 0;
    oWordApplic.Selection.Font.Subscript = 0;

    } public void SetFontName( string strType )
    {
    oWordApplic.Selection.Font.Name = strType;

    }  public void SetFontSize( int nSize )
    {
    oWordApplic.Selection.Font.Size = nSize;

    }  public void InsertPagebreak()
    {
    // VB : Selection.InsertBreak Type:=wdPageBreak
    object pBreak= (int)Word.WdBreakType.wdPageBreak;
    oWordApplic.Selection.InsertBreak(ref pBreak );
    } // Go to a predefined book, if the book doesn't exists the application will raise an error public void GotoBookMark( string strBookMarkName)
    {
    // VB :  Selection.GoTo What:=wdGoToBook, Name:="nome"
    object missing = System.Reflection.Missing.Value; object Book = (int)Word.WdGoToItem.wdGoToBook;
    object NameBookMark = strBookMarkName;
    oWordApplic.Selection.GoTo(ref Book, ref missing, ref missing,ref NameBookMark);
    } public void GoToTheEnd( )
    {
    // VB :  Selection.EndKey Unit:=wdStory
    object missing = System.Reflection.Missing.Value;
    object unit ;
    unit = Word.WdUnits.wdStory ;
    oWordApplic.Selection.EndKey ( ref unit, ref missing);


    public void GoToTheBeginning( )
    {
    // VB : Selection.HomeKey Unit:=wdStory
    object missing = System.Reflection.Missing.Value;
    object unit ;
    unit = Word.WdUnits.wdStory ;
    oWordApplic.Selection.HomeKey ( ref unit, ref missing);

    }  public void GoToTheTable(int ntable )
    {
    // Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=1, Name:=""

    object missing = System.Reflection.Missing.Value;
    object what;
    what = Word.WdUnits.wdTable ;
    object which;
    which = Word.WdGoToDirection.wdGoToFirst;
    object count;
    count = 1 ;
    oWordApplic.Selection.GoTo( ref what, ref which, ref count, ref missing);
    oWordApplic.Selection.Find.ClearFormatting(); oWordApplic.Selection.Text = "";


    }  public void GoToRightCell( )
    {
    // Selection.MoveRight Unit:=wdCell

    object missing = System.Reflection.Missing.Value;
    object direction;
    direction = Word.WdUnits.wdCell;
    oWordApplic.Selection.MoveRight(ref direction,ref missing,ref missing);
    }  public void GoToLeftCell( )
    {
    // Selection.MoveRight Unit:=wdCell

    object missing = System.Reflection.Missing.Value;
    object direction;
    direction = Word.WdUnits.wdCell;
    oWordApplic.Selection.MoveLeft(ref direction,ref missing,ref missing);
    }  public void GoToDownCell( )
    {
    // Selection.MoveRight Unit:=wdCell

    object missing = System.Reflection.Missing.Value;
    object direction;
    direction = Word.WdUnits.wdLine;
    oWordApplic.Selection.MoveDown(ref direction,ref missing,ref missing);
    }  public void GoToUpCell( )
    {
    // Selection.MoveRight Unit:=wdCell

    object missing = System.Reflection.Missing.Value;
    object direction;
    direction = Word.WdUnits.wdLine;
    oWordApplic.Selection.MoveUp(ref direction,ref missing,ref missing);

    // this function doesn't work
    public void InsertPageNumber( string strType, bool bHeader )
    {
    object missing = System.Reflection.Missing.Value;
    object alignment ;
    object bFirstPage = false;
    object bF = true;
    //if (bHeader == true)
    //WordApplic.Selection.HeaderFooter.PageNumbers.ShowFirstPageNumber = bF;
    switch (strType)
    {
    case "Center":
    alignment = Word.WdPageNumberAlignment.wdAlignPageNumberCenter;
    //WordApplic.Selection.HeaderFooter.PageNumbers.Add(ref alignment,ref bFirstPage);
    //Word.Selection objSelection = WordApplic.pSelection;

    oWordApplic.Selection.HeaderFooter.PageNumbers.Item(1).Alignment = Word.WdPageNumberAlignment.wdAlignPageNumberCenter;
    break;
    case "Right":
    alignment = Word.WdPageNumberAlignment.wdAlignPageNumberRight;
    oWordApplic.Selection.HeaderFooter.PageNumbers.Item(1).Alignment = Word.WdPageNumberAlignment.wdAlignPageNumberRight;
    break;
    case "Left":
    alignment = Word.WdPageNumberAlignment.wdAlignPageNumberLeft;
    oWordApplic.Selection.HeaderFooter.PageNumbers.Add(ref alignment,ref bFirstPage);
    break;
    }
                
    }
    }
    }
      

  19.   

    接上:
    public class CCExcelApp
    {   private Excel.ApplicationClass oExcelApplic; 
        private Excel.Workbook  oXsl; public CCExcelApp()

    oExcelApplic=new Excel.ApplicationClass();
    }
    public  void  Open( string strFileName)
    {
    string fileName = strFileName;
    object readOnly = false;
    //object isVisible = true;
    object missing = System.Reflection.Missing.Value; oXsl = oExcelApplic.Workbooks.Open( fileName,  missing, readOnly, 
     missing,  missing,  missing, missing,  missing,  missing, 
     missing,  missing,  missing, missing);
    oXsl.Activate();
    }
    public  void Quit()
            {
    object missing = System.Reflection.Missing.Value;
    oXsl.Close( missing, missing, missing);

        oExcelApplic.Application.Workbooks.Close(); 
         oExcelApplic.Application.Quit();
    oExcelApplic.Quit(); 

    }
    public  void SaveAs(string strFileName )
    {
    object missing = System.Reflection.Missing.Value;
    object fileName = strFileName; oXsl.SaveAs( fileName,  missing, missing,  missing, missing, missing,  Excel.XlSaveAsAccessMode.xlNoChange,
     missing, missing, missing,  missing);
    } // Save the document in HTML format
    public  void SaveAsHtml(string strFileName )
    {
    object missing = System.Reflection.Missing.Value;
    string fileName = strFileName;
    //object Format = (int)Word.WdSaveFormat.wdFormatHTML;
                object Format=Excel.XlFileFormat.xlHtml;  
    // object Format=Excel.XlHtmlType.xlHtmlChart; 
    //object Format=(int)Excel.XlHtmlType.xlHtmlList; //此种格式将乱码
    //object Format=(int)Excel.XlHtmlType.xlHtmlCalc; //将乱码
                  //object Format=Excel.XlHtmlType.xlHtmlStatic; //异常
    oXsl.SaveAs(fileName,Format, missing,  missing, missing, missing,  Excel.XlSaveAsAccessMode.xlNoChange,
    missing, missing,missing,  missing);
    }

    }