把word 的内容读出来,显示在网页上。
读execl的代码请不要是网上流行的读第一列的数据的。
老大!!
给代码好吗?
读execl的代码请不要是网上流行的读第一列的数据的。
老大!!
给代码好吗?
解决方案 »
- 请教一个有关CacheDependency的问题,如可则加高分【【【高分求解】】】
- 都来推荐几个免费的ASP.NET空间
- 急!最近做了网站,传上去之后,刚开可以没问题,过段时间就不行了,我再重新传一下又可以了(提示Object reference not set to an instance of an object. ),谢谢!
- 请教一简单问题
- B/S系统能否现实类似注册码功能?限制用户的发布量!
- HyperLink控件,如何在鼠标经过的时候显示另一个图标?
- 请教聊天儿室的制作
- 难道这么做会有问题????????????("第"&j&"行,第"&i&"列")
- 高分求助,如能解决,再给200分。所有的机器配置都一样,javascript脚本在有些机器上执行不了
- 如何动态显示数据,在水晶报表中??
- 用asp.net操作word,始终有winword.exe进程杀不掉。ZHANG9652(剑神独孤求败)大侠请进,关于编写组件控制word的思路。
- 高分求HTML的TABLE导出EXCEL,解决立即结贴!
<%@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数据库。
<%@ 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>
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
大哥们,help!
因为我自己搞定了。
可以读出显示,存为网页,建立word文档,写入内容。
要得留邮箱。
谢谢
如果excel是不规则文件,比如有些合并单元,怎么办?
大哥等人发过来啊
急切盼望回复
对于不规则的excel的操作,我是能实现的,一个是代码的问题,还有一个是要在服务器上配置一下,不然不代码没有权限访问excel
[email protected]
谢谢!!!一定要发啊
不规则表结构也就算了,
如果列里的数据类型不一样,我看你们怎办呢
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;
}
}
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;
}
}
}
}
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);
}
}