Fckeditor 怎么添加导入word文档的功能???急急急。。。

shaoboyy 2009-10-20 09:10:57
做的东西里要有一个在fckeditor里导入文档的功能。

在这里我们要实现直接导入word文档,如果其中包含图片,则自动分离图片并上传到服务器后在fckeditor中显示.

搞了2天,网上有和ASP.NET的解决办法,

java的一点头绪都没有,

参考这个http://www.javaeye.com/topic/150487 还是搞不出来。

望高手解决一下呀。。。

不胜感激。。。。。。。。。。。。

急急急。。。。。。。。。



我的邮箱343269876@qq.com
...全文
3179 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xwork1111 2010-10-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 ghl2000ok 的回复:]
using System;
using System.Web;
using System.Web.UI.HtmlControls;
using Microsoft.Office.Interop.Word;
using System.IO;

public partial class ImportWord : System.Web.UI.Page
{
//Html文件名
……
[/Quote]
您好!这好像是.net的吧,有java的吗?
zerolost0413 2010-08-23
  • 打赏
  • 举报
回复
学习了!
liu13718696698 2010-05-25
  • 打赏
  • 举报
回复
检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80040154。
ghl2000ok 2009-11-25
  • 打赏
  • 举报
回复
把Microsoft.Office.Interop.Word.dll文件复制到你工程项目的bin目录。

在fckconfig.js中加载组件。

在fckeditor的fckconfig.js中加入如下内容

FCKConfig.Plugins.Add( 'ImportWord' , 'zh-cn') ; //加载导入Word组件

在工具栏中添加导入word按钮。

fckconfig.js中:
找到这行中 FCKConfig.ToolbarSets["Default"] = [...

'Paste','PasteText','PasteWord',在PasteWord后插入'ImportWord'.
ghl2000ok 2009-11-25
  • 打赏
  • 举报
回复
using System;
using System.Web;
using System.Web.UI.HtmlControls;
using Microsoft.Office.Interop.Word;
using System.IO;

public partial class ImportWord : System.Web.UI.Page
{
//Html文件名
private string _htmlFileName;

protected void Page_Load(object sender, EventArgs e)
{

}

/// <summary>
/// 上传Word文档
/// </summary>
/// <param name="inputFile"></param>
private string UpLoadFile(HtmlInputFile inputFile)
{
//建立上传对象
HttpPostedFile postedFile = inputFile.PostedFile;

string fileName = Path.GetFileName(postedFile.FileName);
string fileExtension = Path.GetFileNameWithoutExtension(fileName);

//上传图片保存Base路径 如果修改此路径需要同时修改图片地址替换路径(在212行附件)
string phyPath = Server.MapPath("~/") + "FckUpload\\ImportWord\\0\\";

//判断路径是否存在,若不存在则创建路径
DirectoryInfo upDir = new DirectoryInfo(phyPath);
if (!upDir.Exists)
{
upDir.Create();
}

//判断文件是否存在,存在则提示文件存在并退出
DirectoryInfo upPFName = new DirectoryInfo(phyPath + fileExtension + ".files\\");
if (upPFName.Exists)
{
return "false";
}
//保存文件
try
{
postedFile.SaveAs(phyPath + fileName);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
return phyPath + fileName;
}

/// <summary>
/// word转成html
/// </summary>
/// <param name="wordFileName"></param>
private static string WordToHtml(object wordFileName)
{
//在此处放置用户代码以初始化页面
ApplicationClass word = new ApplicationClass();
Type wordType = word.GetType();
Documents docs = word.Documents;

//打开文件
Type docsType = docs.GetType();
Document doc = (Document)docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null, docs, new[] { wordFileName, true, true });

//转换格式,另存为
Type docType = doc.GetType();

string wordSaveFileName = wordFileName.ToString();
string strSaveFileName = wordSaveFileName.Substring(0, wordSaveFileName.Length - 3) + "html";
object saveFileName = strSaveFileName;
//下面是Microsoft Word 9 Object Library的写法,如果是10,可能写成如下
/*
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[]{saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML});
*/
///其它格式:
///wdFormatHTML
///wdFormatDocument
///wdFormatDOSText
///wdFormatDOSTextLineBreaks
///wdFormatEncodedText
///wdFormatRTF
///wdFormatTemplate
///wdFormatText
///wdFormatTextLineBreaks
///wdFormatUnicodeText
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new[] { saveFileName, WdSaveFormat.wdFormatHTML });

docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod,
null, doc, null);

//退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
null, word, null);

return saveFileName.ToString();
}

/// <summary>
/// 上传并处理word文档
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnUpload_Click(object sender, EventArgs e)
{
string strFilename = UpLoadFile(fileWord);
if (strFilename == "false")
{
Page.ClientScript.RegisterStartupScript(Page.ClientScript.GetType(), "ok ", "alert('word文档已经存在,请换文件名上传') ", true);
return;
}
_htmlFileName = WordToHtml(strFilename);

FindUsedFromHtml(GetHtml(_htmlFileName),strFilename);

//删除文件
File.Delete(_htmlFileName);
File.Delete(strFilename);
}

/// <summary>
/// 读取html文件,返回字符串
/// </summary>
/// <param name="strHtmlFileName"></param>
/// <returns></returns>
private static string GetHtml(string strHtmlFileName)
{
System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("gb2312");

StreamReader sr = new StreamReader(strHtmlFileName, encoding);

string str = sr.ReadToEnd();

sr.Close();

return str;
}
/// <summary>
///
/// </summary>
/// <param name="strHtml"></param>
/// <param name="strFileName"></param>
/// <returns></returns>
private void FindUsedFromHtml(string strHtml, string strFileName)
{
// stytle 部分
int index = 0;
int intStyleStart = 0;
int intStyleEnd = 0;

while (index < strHtml.Length)
{
int intStyleStartTmp = strHtml.IndexOf("<style>", index);
if (intStyleStartTmp == -1)
{
break;
}
int intContentStart = strHtml.IndexOf("<!--", intStyleStartTmp);
if (intContentStart - intStyleStartTmp == 9)
{
intStyleStart = intStyleStartTmp;
break;
}
index = intStyleStartTmp + 7;
}

index = 0;
while (index < strHtml.Length)
{
int intContentEndTmp = strHtml.IndexOf("-->", index);
if (intContentEndTmp == -1)
{
break;
}
int intStyleEndTmp = strHtml.IndexOf("</style>", intContentEndTmp);
if (intStyleEndTmp - intContentEndTmp == 5)
{
intStyleEnd = intStyleEndTmp;
break;
}
index = intContentEndTmp + 4;
}

string strStyle = strHtml.Substring(intStyleStart, intStyleEnd - intStyleStart + 8);

// Body部分
int bodyStart = strHtml.IndexOf("<body");
int bodyEnd = strHtml.IndexOf("</body>");

string strBody = strHtml.Substring(bodyStart, bodyEnd - bodyStart + 7);

//替换图片地址
string fullName = strFileName.Substring(strFileName.LastIndexOf("\\") + 1);
string fullExtension = Path.GetExtension(fullName);
string strOld = string.Empty;
switch (fullExtension)
{
case ".docx":
strOld = fullName.Replace("docx", "files").Replace(" ", "%20");
break;
case ".doc":
strOld = fullName.Replace("doc", "files").Replace(" ", "%20");
break;
case ".DOCX":
strOld = fullName.Replace("DOCX", "files").Replace(" ", "%20");
break;
case ".DOC":
strOld = fullName.Replace("DOC", "files").Replace(" ", "%20");
break;
}
string strNew = Page.Request.ApplicationPath + "/FckUpload/ImportWord/0/" + strOld;

strBody = strBody.Replace(strOld, strNew);
strBody = strBody.Replace("v:imagedata", "img");
strBody = strBody.Replace("</v:imagedata>", "");

//Sgxcn临时调试用-但不可去掉
TextArea1.InnerText = strStyle;
Textarea2.InnerText = strBody;

//更改信息
pnlOk.Visible = true;
pnlUpload.Visible = false;
}
}
ghl2000ok 2009-11-25
  • 打赏
  • 举报
回复
在fckeditor-editor-plugins下添加ImportWord文件夹
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ImportWord.aspx.cs" Inherits="ImportWord" %>

<!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 id="Head1" runat="server">
<title>Untitled Page</title>

<script src="../../dialog/common/fck_dialog_common.js" type="text/javascript"></script>

<script type="text/javascript">

var oEditor = window.parent.InnerDialogLoaded() ;

// Gets the document DOM
var oDOM = oEditor.FCK.EditorDocument ;

var ImportOk = false;

// Fired when the window loading process is finished. It sets the fields with the
// actual values if a table is selected in the editor.
window.onload = function()
{
//oEditor.FCKLanguageManager.TranslatePage(document);

window.parent.SetOkButton( true ) ;
window.parent.SetAutoSize( true ) ;
}

// Fired when the user press the OK button
function Ok()
{
if(!ImportOk)
{
if(document.getElementById("fileWord").value == "")
{
alert("请先选择Word文件。");
return false;
}
else
{
alert("请单击“开始导入”按钮。");
return false;
}
}

var oActiveEl = oEditor.FCK.EditorDocument.createElement( 'SPAN' ) ;
oActiveEl.innerHTML = document.getElementById('TextArea1').value + document.getElementById('TextArea2').value;
oEditor.FCKUndo.SaveUndoStep() ;
oActiveEl = oEditor.FCK.InsertElement( oActiveEl ) ;

return true;
}
</script>

</head>
<body>
<form id="form1" method="post" runat="server">
<asp:Panel ID="pnlUpload" runat="server">
请选择您要导入的word文件:
<div style="margin:10px">
<input id="fileWord" runat="server" type="file" style="width: 300px"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="fileWord"
Display="Dynamic" ErrorMessage="您还没有选择要上传的Word文档。" SetFocusOnError="True"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="fileWord"
Display="Dynamic" ErrorMessage="您选择的文件不是.doc(Word)文档。" SetFocusOnError="True"

ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.doc|.DOC|.docx|.DOCX)$"></asp:RegularExpressionValidator><br />
</div>

<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="开始导入" />
</asp:Panel>
<asp:Panel ID="pnlOk" runat="server" Visible="False">
Word文件已经导入成功,单击“确定”导入到编辑器中,单击“取消”将放弃导入操作。
<script type="text/javascript">ImportOk = true;</script>
</asp:Panel>

<div style="display:none">
<textarea id="TextArea1" style="width: 648px; height: 220px" runat="server"></textarea><br />
<textarea id="Textarea2" style="width: 648px; height: 201px" runat="server"></textarea>
</div>

</form>
</body>
</html>
shaoboyy 2009-11-22
  • 打赏
  • 举报
回复
无功而返······
guodongbingtuan 2009-10-21
  • 打赏
  • 举报
回复
也在弄这个,郁闷中........
出来告一声..
此文档的目录结构: 1 FCKeditor的下载及介绍 4 1.1 下载地址 4 1.2 FCKeditor下载包的介绍 4 2 FCKeditor的目录和文件精简 4 3 在页面创建FCKeditor 4 3.1 Js创建FCKeditor实例: 4 3.1.1 方法一:内嵌方法(推荐) 4 3.1.2 方法二:替换页面中的Textarea 5 3.1.3 方法三:适合于Ajax的调用方法 6 3.1.4 Js中FCKeditor对象的属性(集合)和方法 6 3.1.4.1 属性 6 3.1.4.2 集合 7 3.1.4.3 方法 7 3.1.5 FCKeditor的JS构造器 9 3.1.6 将从后台读取的数据显示在FCKeditor中 9 3.2 在Jsp中通过自定义标签创建: 9 3.3 FCKeditor API 调用 10 3.4 适时打开编辑器 10 4 修改FCKeditor的配置: 11 4.1 方法一:修改fckconfig.js 文件 11 4.2 方法二:使用一个额外的配置文件覆盖默认配置 11 4.3 配置的加载顺序 11 4.4 提示 11 4.5 一般需要修改的配置项 11 4.5.1 默认语言 11 4.5.2 自定义ToolbarSet, 去掉一些不需要的功能 12 4.5.3 加上几种常用的字体 13 4.5.4 修改“回车” 和 “Shift + 回车”的换行行为 13 4.5.5 修改编辑区的样式文件 14 4.5.6 更换表情图片 14 4.5.7 编辑区域的右键菜单功能 14 4.6 fckconfig.js配置参数选项说明 15 4.7 自定义工具栏按钮 17 4.8 自定义右键菜单 18 5 文件上传问题 19 5.1 开启和关闭文件上传功能(fckconfig.js) 19 5.2 文件上传的基本使用 19 5.3 上传中文文件名的文件会出现乱码 20 5.4 创建中文名目录会出现乱码 21 5.5 引用中文名文件的图片不能正常显示 21 5.6 控件允许上传的文件的类型 22 5.7 控制上传的文件的大小 22 5.8 增加文件删除功能 23 6 超连接重定位问题 25 7 使用FCKeditor的API 26 7.1 获得FCKeditor的实例 26 7.1.1 获得当前页FCKeditor实例 26 7.1.2 从FCKeditor的弹出窗口中获得FCKeditor实例 26 7.1.3 从框架页面的子框架中获得其它子框架的FCKeditor实例 26 7.1.4 从页面弹出窗口中获得父窗口的FCKeditor实例 26 7.2 常见的Js方法调用 27 7.2.1 插入HTML到FCKeditor 27 7.2.2 设置FCKeditor的内容(HTML) 27 7.2.3 获取FCKeditor中的XHTML 27 7.2.4 获取FCKeditor中的innerHTML和innerText 27 7.2.5 执行指定动作 28 7.2.6 统计编辑器中内容的字数 29 7.2.7 检查FCKeditor中的内容是否有改动 29 7.2.8 将FCKeditor中的内容是否有改动的值重新设置 29 8 外联编辑条(多个编辑域共用一个编辑条) 29 9 解释fck样式(CSS)的工作原理 30 10 获取FCKeditor中插入的图片 31

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧