📄 webeditor1.js
字号:
myRange.ParagraphFormat.LineSpacingRule =1.5;
myRange.ParagraphFormat.Alignment=1;
myRange.font.ColorIndex=1;
mtext="帝龙科技电子政务文件";
webform.WebOffice.ActiveDocument.Application.Selection.Range.InsertAfter (mtext+"\n");
myRange=webform.WebOffice.ActiveDocument.Paragraphs(1).Range;
myRange.ParagraphFormat.LineSpacingRule =1.5;
//myRange.Select();
myRange.Font.ColorIndex=6;
myRange.Font.Name="仿宋_GB2312";
myRange.font.Bold=true;
myRange.Font.Size=50;
myRange.ParagraphFormat.Alignment=1;
//myRange=myRange=webform.WebOffice.ActiveDocument.Paragraphs(1).Range;
webform.WebOffice.ActiveDocument.PageSetup.LeftMargin=70;
webform.WebOffice.ActiveDocument.PageSetup.RightMargin=70;
webform.WebOffice.ActiveDocument.PageSetup.TopMargin=70;
webform.WebOffice.ActiveDocument.PageSetup.BottomMargin=70;
}
//保存定稿文件
function UpdateFile(){
try{
webform.WebOffice.UpdateFile();
if (webform.WebOffice.Error!=""){
alert(webform.WebOffice.Status+webform.WebOffice.Error);
}
}catch(e){}
StatusMsg(webform.WebOffice.Status);
}
//从服务器上导入数据到文档中
function InportText(){
var mText;
webform.WebOffice.SendToServer("INPORTTEXT");
if (webform.WebOffice.Error==""){
mText=webform.WebOffice.GetMsgByName("CONTENT");
webform.WebOffice.ActiveDocument.Application.Selection.Range.InsertAfter(mText);
alert("导入文本成功");
}
StatusMsg(webform.WebOffice.Status);
}
//导出所有文档文本给服务器
function ExportText(){
var mText=webform.WebOffice.ActiveDocument.Content.Text;
webform.WebOffice.SetMsgByName("CONTENT",mText);
webform.WebOffice.SendToServer("EXPORTTEXT");
if (webform.WebOffice.Error==""){
alert("导出文本成功");
}
StatusMsg(webform.WebOffice.Status);
}
//根据标签名称查找标签
function FindBookmarks(mPosition)
{
var mBookObject,mBookName,mBookIdx;
if (webform.WebOffice.FileType==".doc"){
for (mBookIdx = 1; mBookIdx<=webform.WebOffice.ActiveDocument.Bookmarks.Count;mBookIdx++){
mBookName = webform.WebOffice.ActiveDocument.Bookmarks.Item(mBookIdx).Name;
if (mBookName==mPosition) {
mBookObject = webform.WebOffice.ActiveDocument.Bookmarks.Item(mBookIdx).Range;
break;
}
}
}
return (mBookObject);
}
//插入服务器图片
function InsertImage(vLabName,vImgName,vTrans,vZOrder)
{
//取得文件目录
var mFilePath=webform.WebOffice.MsgFilepath;
var mImgShape=null;
var mPassword=null;
//清除所有设置变量
webform.WebOffice.MsgTextClear();
//设置要插入的图片名称
webform.WebOffice.SetMsgByName("IMAGENAME",vImgName);
//发送到服务器上
webform.WebOffice.SendToServer("INSERTIMAGE");
//如果没有错误
if (webform.WebOffice.Error==""){
//将服务器返回的图片保存
webform.WebOffice.MsgFileSave(mFilePath+vImgName);
//如果没有错误
if (webform.WebOffice.Error==""){
//如果是word文档
if (webform.WebOffice.FileType==".doc"){
var mInlineShapes=null;
var mBookMark=FindBookmarks(vLabName);
if (mBookMark){
mInlineShares=mBookMark.InlineShapes.AddPicture(mFilePath+vImgName);
}else{
mInlineShares=webform.WebOffice.ActiveDocument.Application.Selection.InlineShapes.AddPicture(mFilePath+vImgName);
}
mImgShape=mInlineShares.ConvertToShape();
mImgShape.Select();
mImgShape.PictureFormat.TransparentBackground = vTrans;
mImgShape.PictureFormat.TransparencyColor = 16777215;
mImgShape.Fill.Visible = false;
mImgShape.WrapFormat.Type = 3;
mImgShape.ZOrder(vZOrder);
}
//如果是Excel文档
if (webform.WebOffice.FileType==".xls"){
webform.WebOffice.ActiveDocument.ActiveSheet.Pictures.Insert(mFilePath+vImgName).Select();
mImgShape =webform.WebOffice.ActiveDocument.Application.Selection.ShapeRange;
mImgShape.PictureFormat.TransparentBackground = vTrans;
mImgShape.PictureFormat.TransparencyColor = 16777215;
mImgShape.Fill.Visible = false;
mImgShape.ZOrder(vZOrder);
}
}
//清除文件
webform.WebOffice.MsgFileClear(mFilePath+vImgName);
}
StatusMsg(webform.WebOffice.Status+webform.WebOffice.Error);
}
//套用模版定稿
function InsertFile()
{
//var mDialogUrl = "Version/VersionList.jsp?RecordID="+webform.WebOffice.RecordID;
//var mObject = new Object();
// mObject.FileID = "";
// mObject.Result = false;
// window.showModalDialog(mDialogUrl, mObject, "dialogHeight:280px; dialogWidth:420px;center:yes;scroll:no;status:no;");
//if (mObject.Result){
//取得目录名称
var mFilePath=webform.WebOffice.MsgFilepath;
//取得文件类型
var mFileName=webform.WebOffice.RecordID+webform.WebOffice.FileType;
var mBookRange;
//保存当前文件
webform.WebOffice.Save(mFilePath+mFileName,true);
//如果没有问题
if (webform.WebOffice.Error==""){
//清除所有设置变量
webform.WebOffice.MsgTextClear();
//设置需要调用的模版名称
webform.WebOffice.SetMsgByName("TEMPNAME","模板一.doc");
//发送该信息到服务器上
webform.WebOffice.SendToServer("INSERTFILE");
//如果没有错误
if (webform.WebOffice.Error==""){
//关闭当前文件
webform.WebOffice.Close();
//保存模版文件
webform.WebOffice.MsgFileSave(gFileName);
//如果没有错误
if (webform.WebOffice.Error==""){
//打开模版文件
webform.WebOffice.Open(gFileName,true);
//查找需要插入的位置(标签)
var mPosition=webform.WebOffice.GetMsgByName('POSITION');
if (mPosition.length>0){
mBookRange = FindBookmarks(mPosition);
}else{
mBookRange = webform.WebOffice.ActiveDocument.Range.Application.Selection;
}
//将原工作文档插入到该位置
mBookRange.InsertFile(mFilePath+mFileName);
}
}else{
alert(webform.WebOffice.Error);
}
}
//清楚文件
webform.WebOffice.MsgFileClear(mFilePath+mFileName);
StatusMsg(webform.WebOffice.Status)
}
//作用:表格生成及填充
function SetWordTable(){
var mText="",mName="",iColumns,iCells,iTable;
//清除所有设置变量
webform.WebOffice.MsgTextClear();
//发送到服务器上
webform.WebOffice.SendToServer("WORDTABLE");
//如果没有错误
if (webform.WebOffice.Error==""){
//取得列
iColumns = webform.WebOffice.GetMsgByName("COLUMNS");
//取得行
iCells = webform.WebOffice.GetMsgByName("CELLS");
//生成表格
iTable=webform.WebOffice.ActiveDocument.Tables.Add(webform.WebOffice.ActiveDocument.Application.Selection.Range,iCells,iColumns);
for (var i=1; i<=iColumns; i++)
{
for (var j=1; j<=iCells; j++)
{
mName=i.toString()+j.toString();
//取得表格内容
mText=webform.WebOffice.GetMsgByName(mName);
//填充单元值
iTable.Columns(i).Cells(j).Range.Text=mText;
}
}
}
StatusMsg(webform.WebOffice.Status);
}
//打印黑白
function WebWordPrintBlackAndWhile(){
var i,n;
//图片变黑白
i=0;
n=webform.WebOffice.ActiveDocument.Shapes.Count;
for (var i=1; i<=n; i++)
{
webform.WebOffice.ActiveDocument.Shapes.Item(i).PictureFormat.ColorType=3;
}
i=0;
n=webform.WebOffice.ActiveDocument.InlineShapes.Count;
for (var i=1; i<=n; i++)
{
webform.WebOffice.ActiveDocument.InlineShapes.Item(i).PictureFormat.ColorType=3;
}
//文字变黑白
webform.WebOffice.ActiveDocument.Application.Selection.WholeStory();
webform.WebOffice.ActiveDocument.Application.Selection.Range.Font.Color = 0;
}
//作用:统计页数
function WebDocumentPageCount(){
if (webform.WebOffice.FileType==".doc"){
var intPageTotal;
intPageTotal = webform.WebOffice.ActiveDocument.Application.ActiveDocument.BuiltInDocumentProperties(14);
alert("文档页总数:"+intPageTotal);
}
if (webform.WebOffice.FileType==".wps"){
var intPageTotal;
intPageTotal = webform.WebOffice.WebObject.PagesCount();
alert("文档页总数:"+intPageTotal);
}
}
//生成新Word
function WebInsertFiles(){
var i;
for (i=3;i>0;i--){
//取得目录名称
var mFilePath=webform.WebOffice.MsgFilepath;
//取得文件类型
var mFileName=webform.WebOffice.RecordID+webform.WebOffice.FileType;
var mBookRange;
//保存当前文件
webform.WebOffice.Save(mFilePath+mFileName,true);
//如果没有问题
if (webform.WebOffice.Error==""){
//清除所有设置变量
webform.WebOffice.MsgTextClear();
//设置需要调用的模版名称
webform.WebOffice.SetMsgByName("SUBFILE",i+".doc");
//发送该信息到服务器上
webform.WebOffice.SendToServer("INSERTFILEALL");
//如果没有错误
if (webform.WebOffice.Error==""){
//关闭当前文件
webform.WebOffice.Close();
//保存模版文件
webform.WebOffice.MsgFileSave(gFileName);
//如果没有错误
if (webform.WebOffice.Error==""){
//打开模版文件
webform.WebOffice.Open(gFileName,true);
//查找需要插入的位置(标签)
var mPosition=webform.WebOffice.GetMsgByName('POSITION');
if (mPosition.length>0){
mBookRange = FindBookmarks(mPosition);
}else{
mBookRange = webform.WebOffice.ActiveDocument.Range.Application.Selection;
}
//将原工作文档插入到该位置
mBookRange.InsertFile(mFilePath+mFileName);
}
}else{
alert(webform.WebOffice.Error);
}
}
//清楚文件
webform.WebOffice.MsgFileClear(mFilePath+mFileName);
StatusMsg(webform.WebOffice.Status)
}
}
//插入文字
function IText(){
var mText=window.prompt("请输入内容:","测试内容");
if (mText==null){
return (false);
}
else
{
//下面为显示选中的文本
//alert(webform.WebOffice.ActiveDocument.Application.Selection.Range.Text);
//下面为在当前光标出插入文本
webform.WebOffice.ActiveDocument.Range(0,0).insertAfter(mText+"\n");
//webform.WebOffice.ActiveDocument.Application.Selection.Range.InsertAfter (mText+"\n");
//下面为在第一段后插入文本
//webform.WebOffice.ActiveDocument.Application.ActiveDocument.Range(1).InsertAfter(mText);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -