向[Sandy945]提问 非哥问个问题我要把word文档中的内容读取出来在页面上显示怎么实现啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System;using System.IO;using System.Collections;namespace TextFileReader_csharp{ /// <summary> /// Summary description for Class1. /// </summary> class Class1 { static void Main(string[] args) { StreamReader objReader = new StreamReader("c:\\test.doc"); string sLine = ""; ArrayList arrText = new ArrayList(); while (sLine != null) { sLine = objReader.ReadLine(); if (sLine != null) arrText.Add(sLine); } objReader.Close(); foreach (string sOutput in arrText) Console.WriteLine(sOutput); Console.ReadLine(); } }} 可以利用office组件http://topic.csdn.net/t/20040102/11/2625860.html 我们之前项目用一个类似于word的控件,但是是收费的,可以很方便的读取word的内容,然后在网页中打开后,可以随意编辑,保存。 我读取出来时乱码 public void ReadWord() { DataTable DT=DownMethod.GetDataByID(1,"ZJDownload"); //文件路径 path = DT.Rows[0][1].ToString(); StreamReader objReader = new StreamReader(path); string sLine = ""; ArrayList arrText = new ArrayList(); while (sLine != null) { sLine = objReader.ReadLine(); if (sLine != null) arrText.Add(sLine); } objReader.Close(); foreach (string sOutput in arrText) TextBox1.Text += sOutput; // Console.WriteLine(sOutput); //Console.ReadLine(); } 恩,这种方式只能读取文字,有图片或是表格就乱码。你参考一个这个吧 http://liuway.javaeye.com/blog/431535 public bool Open(string strFileName) { return this.Open(strFileName, true); } 你主要是调用这个函数就可以了 用控件吧 千航的不错,可惜收费google那个在线文档好像也是可以读取/保存word的 不知道咋弄的 叶子能不能把word转换为pdf然后在页面中读取出来了 我回来了,这个可以你看看这个http://blog.hoyai.com/?p=16 打开word获取内容string path=Server.MapPath("a.doc"); FileInfo file=new FileInfo(path); FileStream myfileStream=new FileStream(path,FileMode.Open,FileAccess.Read); byte[] filedata=new Byte[file.Length]; myfileStream.Read(filedata,0,(int)(file.Length)); myfileStream.Close(); 或Word.Application app = new Microsoft.Office.Interop.Word.Application(); Word.Document doc = null; WORD生成PDF参考word在线编辑可使用office 编辑器 如DSOFramer,officecontrol.cab 就想excel表格那样万一不行纯文本怎么弄 纯文本用js 读取 然后输出就可以了。excel表格那样 指的是什么样 就是表格啊例如 姓名 性别 年龄 备注... aa 男 34 dfada bb 女 25 dfsfs这样的非哥你说的纯文本JS读取怎么实现啊 <html><div id='div'></div><input type="button" value="读取Word" onclick='readWord();' /></html><script language="javascript">function readWord(){ var WordApp,WordDoc,str; WordApp = new ActiveXObject("Word.application"); WordDoc = WordApp.Documents.Open("C:\\a.doc"); str=WordDoc.content.text; WordDoc.close(); WordApp.quit(); document.getElementById('div').innerHTML=str; }</script> 网页错误详细信息用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)时间戳: Mon, 9 Nov 2009 08:31:00 UTC消息: Automation 服务器不能创建对象行: 10字符: 3代码: 0URI: http://localhost:1607/WebSite4/jquery/HTMLPage13.htm消息: Automation 服务器不能创建对象行: 10字符: 3代码: 0URI: http://localhost:1607/WebSite4/jquery/HTMLPage13.htm WordApp = new ActiveXObject("Word.application");我看了下是这个地方有问题 来个C# 版本的<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title></head><body> <form id="form1" runat="server"> <asp:Literal ID="lit" runat="server"></asp:Literal> </form></body></html>protected void Page_Load(object sender, EventArgs e) { lit.Text = GetText(Server.MapPath("a.doc")); } public string GetText(string fileName) { //实例化COM Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); object fileobj = fileName; object nullobj = System.Reflection.Missing.Value; //打开指定文件(不同版本的COM参数个数有差异,一般而言除第一个外都用nullobj就行了) Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref fileobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj ); //取得doc文件中的文本 string outText = doc.Content.Text; //关闭文件 doc.Close(ref nullobj, ref nullobj, ref nullobj); //关闭COM wordApp.Quit(ref nullobj, ref nullobj, ref nullobj); //返回 return outText; }记得引用DLL, 我用的是 12.0 的,11.0 应该也没问题的 谢谢非哥C#版本的可以但是js的不可以 Sandy 945 的方法确实可以,我验证成功了。连html代码都能读出来。 Textbox中多个空格如何保留??? asp. net treeview 效率太慢了,怎么变快呀 Calendar 绑定一个日期 100分!求解一问题~~~在线等!!!!!!!!!! 怎么保存用户控件的状态? 为什么我们的iis经常重启? 我使用水晶报表,运行时,怎么提示这个错 怎么得到分页的DataGrid中第二页的第一列,第一行的内容 各位高手,如何用javascript函数清空DataGrid中某一行第一个单元格中的数值 请问NWGS支持98吗 (单件模式)单件能否可有子类? asp.net treeview节点显示与隐藏(十万火急)
using System;
using System.IO;
using System.Collections;
namespace TextFileReader_csharp
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
StreamReader objReader = new StreamReader("c:\\test.doc");
string sLine = "";
ArrayList arrText = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
arrText.Add(sLine);
}
objReader.Close();
foreach (string sOutput in arrText)
Console.WriteLine(sOutput);
Console.ReadLine();
}
}
}
http://topic.csdn.net/t/20040102/11/2625860.html
我读取出来时乱码 public void ReadWord()
{
DataTable DT=DownMethod.GetDataByID(1,"ZJDownload");
//文件路径
path = DT.Rows[0][1].ToString();
StreamReader objReader = new StreamReader(path);
string sLine = "";
ArrayList arrText = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
arrText.Add(sLine);
}
objReader.Close();
foreach (string sOutput in arrText)
TextBox1.Text += sOutput;
// Console.WriteLine(sOutput);
//Console.ReadLine(); }
{
return this.Open(strFileName, true);
} 你主要是调用这个函数就可以了
千航的不错,可惜收费google那个在线文档好像也是可以读取/保存word的 不知道咋弄的
能不能把
word转换为pdf
然后在页面中读取出来了
http://blog.hoyai.com/?p=16
string path=Server.MapPath("a.doc");
FileInfo file=new FileInfo(path);
FileStream myfileStream=new FileStream(path,FileMode.Open,FileAccess.Read);
byte[] filedata=new Byte[file.Length];
myfileStream.Read(filedata,0,(int)(file.Length));
myfileStream.Close();
或
Word.Application app = new Microsoft.Office.Interop.Word.Application();
Word.Document doc = null;
WORD生成PDF
参考
word在线编辑可使用
office 编辑器
如DSOFramer,officecontrol.cab
万一不行
纯文本怎么弄
例如
姓名 性别 年龄 备注...
aa 男 34 dfada
bb 女 25 dfsfs这样的非哥你说的
纯文本JS读取怎么实现啊
<html>
<div id='div'>
</div>
<input type="button" value="读取Word" onclick='readWord();' />
</html>
<script language="javascript">
function readWord()
{
var WordApp,WordDoc,str;
WordApp = new ActiveXObject("Word.application");
WordDoc = WordApp.Documents.Open("C:\\a.doc");
str=WordDoc.content.text;
WordDoc.close();
WordApp.quit();
document.getElementById('div').innerHTML=str;
}
</script>
时间戳: Mon, 9 Nov 2009 08:31:00 UTC
消息: Automation 服务器不能创建对象
行: 10
字符: 3
代码: 0
URI: http://localhost:1607/WebSite4/jquery/HTMLPage13.htm
消息: Automation 服务器不能创建对象
行: 10
字符: 3
代码: 0
URI: http://localhost:1607/WebSite4/jquery/HTMLPage13.htm
我看了下
是这个地方有问题
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Literal ID="lit" runat="server"></asp:Literal>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
lit.Text = GetText(Server.MapPath("a.doc"));
} public string GetText(string fileName)
{
//实例化COM
Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
object fileobj = fileName;
object nullobj = System.Reflection.Missing.Value;
//打开指定文件(不同版本的COM参数个数有差异,一般而言除第一个外都用nullobj就行了)
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref fileobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj
);
//取得doc文件中的文本
string outText = doc.Content.Text;
//关闭文件
doc.Close(ref nullobj, ref nullobj, ref nullobj);
//关闭COM
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
//返回
return outText;
}记得引用DLL, 我用的是 12.0 的,11.0 应该也没问题的
非哥
C#版本的可以
但是js的不可以