js打开服务器word文件,javascript打开word文档的方法

首先我们新建一个html文件,并且写一个FileUpLoad以及button控件。

代码如下:

fileUpload

然后,在写一个javascript OpenFile方法。

代码如下:

function OpenFile()

{

if (document.getElementById("flUpload").value.toUpperCase().indexOf(".XLS") != -1)

{

var objExcel;

objExcel = new ActiveXObject("Excel.Application");

objExcel.Visible = true;

objExcel.Workbooks.Open(document.getElementById("flUpload").value);

}

else if (document.getElementById("flUpload").value.toUpperCase().indexOf(".DOC") != -1)

{

var objDoc;

objDoc = new ActiveXObject("Word.Application");

objDoc.Visible = true;

objDoc.Documents.Open(document.getElementById("fileUpload").value);

}

else

{

alert("Please select Word/Excel file only");

return false;

}

}

OK。然后 在IE中就能先选入一个word文档,然后点open,就可以成功打开word文档了。

是不是很简单,貌似只能在IE中使用。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CKEditor默认情况下不支持直接打开Word文件,但您可以使用第三方插件来实现该功能。 一个很好用的插件是CKEditor Word插件,它允许您在CKEditor中打开和编辑Word文件。您可以在GitHub上找到它的源代码和文档:https://github.com/WebSpellChecker/ckeditor-plugin-word-import 以下是使用CKEditor Word插件的步骤: 1. 下载CKEditor Word插件并将其解压缩到您的网站目录中的“plugins”文件夹中。 2. 在CKEditor配置文件中添加插件的路径和名称: ```javascript config.extraPlugins = 'wordimport'; ``` 3. 在需要打开Word文件的页面上,使用以下代码创建CKEditor实例: ```javascript CKEDITOR.replace('editor1', { filebrowserBrowseUrl: '/path/to/wordimport/browse.php', filebrowserUploadUrl: '/path/to/wordimport/upload.php' }); ``` 请注意,此代码假定您已经将CKEditor Word插件的示例文件夹放置在您的网站根目录下的“path/to/wordimport”中。如果您将插件放置在不同的位置,请相应地更改文件路径。 4. 创建一个名为“browse.php”的文件,该文件打开Word文件选择器,允许用户选择要打开文件。以下是一个示例“browse.php”文件的代码: ```php <?php /** * CKEditor Word Import Plugin Example * * This is a simple example of file browser script that can be used with CKEditor * Word Import Plugin to browse for Word files on your server. */ // Define the path to the Word files folder on your server $word_files_folder = '/path/to/word/files'; // Get the list of Word files in the folder $word_files = glob($word_files_folder . '/*.docx'); // Build the response array $response = array(); foreach ($word_files as $word_file) { $response[] = array( 'name' => basename($word_file), 'url' => $word_file ); } // Send the response as JSON header('Content-Type: application/json'); echo json_encode($response); ``` 请注意,此代码假定您已将Word文件放在您的网站根目录下的“path/to/word/files”文件夹中。如果您将文件放置在不同的位置,请相应地更改文件路径。 5. 创建一个名为“upload.php”的文件,该文件将处理上传的Word文件并返回文件的URL。以下是一个示例“upload.php”文件的代码: ```php <?php /** * CKEditor Word Import Plugin Example * * This is a simple example of file upload script that can be used with CKEditor * Word Import Plugin to upload Word files to your server. */ // Define the path to the Word files folder on your server $word_files_folder = '/path/to/word/files'; // Check if the file was uploaded successfully if (!isset($_FILES['upload']) || $_FILES['upload']['error'] != UPLOAD_ERR_OK) { die('Upload failed'); } // Generate a unique file name $filename = uniqid() . '.docx'; // Move the uploaded file to the Word files folder move_uploaded_file($_FILES['upload']['tmp_name'], $word_files_folder . '/' . $filename); // Return the URL of the uploaded file echo '/path/to/word/files/' . $filename; ``` 请注意,此代码假定您已将Word文件放在您的网站根目录下的“path/to/word/files”文件夹中。如果您将文件放置在不同的位置,请相应地更改文件路径。 以上是使用CKEditor Word插件打开Word文件的一般步骤,您可以按照上述步骤进行操作。但请注意,此插件的使用需要您在服务器端进行一些设置和编程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值