AE导出图片并插入到word文档中某一固定位置

本文介绍了一种方法,通过矢量图层中的要素范围来批量裁剪地图图片,并将其自动粘贴到Word文档中指定位置。该过程涉及读取要素范围、导出图像以及使用模板Word文档进行批处理。

按矢量图层中各要素范围批量裁剪图片,并将图像粘贴到word中,将已经存在的图像批量粘贴到已存的word文档中。

void ClipPicToWord()

{

      ILayer pLayer=GetCurrentLayer(); 
      IFeatureLayer=pLayer as IFeatureLayer;
      IFeatureClass pFtClass=pFeatureLayer.FeatureClass;
      IFeature pFeature; 
      IQueryFilter pFilter=new QueryFilter(); 
      pFilter.WhereClause=null; 
      IFeatureCursor pCursor=pFtClass.Search(pFilter,false);
      pFeature=pCursor.NextFeature();
      string pWordPath=@"D:\模版文档.doc"; 

      string strFullPath=pWordPath.Substring(0,pWordPath.LastIndexOf(@"\"));

      while(pFeature!=null) 
      {

 IEnvelop pEnvelop=pFeature.Extent; 

 axMapControl1.ActiveView.Extent=pEnvelop; 

 axMapControl1.Refresh(); 

 int index=pFeature.FindField("JCBH");//唯一标识要素的字段,以此命名图像和word文档 

object name=pFeature.get_value(index); 

string strName=name.ToString();

 int lScreenResolution = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.Resolution; 

int m_OutPutResolution=300; 

IExport pExport = new ExportJPEG() as IExport;

 pExport.ExportFileName=strFullName+@"\"+name; 

pExport.PixelBounds=pEnvelop; 

tagRECT deviceRECT; 

deviceRECT.left=deviceRECT.rop=0; 

deviceRECT.right= axMapControl1.ActiveView.ExportFrame.right * (m_OutPutResolution / lScreenResolution); 

deviceRECT.bottom = axMapControl1.ActiveView.ExportFrame.bottom * (m_OutPutResolution / lScreenResolution); 

IEnvelope pDriverBounds = new Envelope() as IEnvelope; 

pDriverBounds.PutCoords(deviceRECT.left, deviceRECT.bottom, deviceRECT.right, deviceRECT.top);

 pExporter.PixelBounds = pDriverBounds; 

ITrackCancel pCancel = new CancelTracker(); 

pExporter.TrackCancel = pCancel;

 System.Int32 hDC = pExporter.StartExporting(); 

axMapControl1.ActiveView.Output(hDC, (System.Int16)pExporter.Resolution, ref deviceRECT, pEnvelop, pCancel); 

pExporter.FinishExporting(); 

pExporter.Cleanup(); 

pWordPath=@"D:\模版文档.doc"; wordManager.CreateNewDocument(filePath);

 string picturePath = strFullName + "\\" + strName + ".jpg"; 

wordManager.InsertPicture("picture1", picturePath, this.PicWith, this.PicHeight, 1); //书签位置,图片路径,图片宽度,图片高度 

filePath = strFullName + "\\" + strName + ".doc";

 wordManager.SaveDocument(filePath); //文档路径 

pFeature = pCursor.NextFeature();

    wordManager.killWinWordProcess();//结束word进程 

    axMapControl1.Extent = axMapControl1.FullExtent;

WordManager.cs中部分代码: 

//创建新文档

 public void CreateNewDocument(string filePath)

 {

 killWinWordProcess(); 

 wordApp = new Application(); 

 wordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone; 

 wordApp.Visible = false;

 object missing = System.Reflection.Missing.Value;

 object templateName = filePath; 

 wordDoc = wordApp.Documents.Open(ref templateName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

 }

 //保存 

public void SaveDocument(string filePath) 

object fileName = filePath; object format = WdSaveFormat.wdFormatDocument;//保存格式 

object miss = System.Reflection.Missing.Value; wordDoc.SaveAs(ref fileName, ref format, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss); 

//关闭wordDoc,wordApp对象 

object SaveChanges = WdSaveOptions.wdSaveChanges;

 object OriginalFormat = WdOriginalFormat.wdOriginalDocumentFormat; 

object RouteDocument = false;

 wordDoc.Close(ref SaveChanges, ref OriginalFormat, ref RouteDocument); 

wordApp.Quit(ref SaveChanges, ref OriginalFormat, ref RouteDocument); 

}

 //插入图片 

public void InsertPicture(string bookmark, string picturePath, float width, float hight,int n) 

object miss = System.Reflection.Missing.Value; 

object oStart = bookmark; 

Object linkToFile = false;

 //图片是否为外部链接 Object saveWithDocument = true; //图片是否随文档一起保存

 object range = wordDoc.Bookmarks.get_Item(ref oStart).Range;//图片插入位置

 wordDoc.InlineShapes.AddPicture(picturePath, ref linkToFile, ref saveWithDocument, ref range); 

wordDoc.Application.ActiveDocument.InlineShapes[n].Width = width; //设置图片宽度 

wordDoc.Application.ActiveDocument.InlineShapes[n].Height = hight; //设置图片高度 

}

 //结束WORD进程

 public void killWinWordProcess()

 { 

System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("WINWORD"); 

foreach (System.Diagnostics.Process process in processes) 

     bool b = process.MainWindowTitle == ""; 

    if (process.MainWindowTitle == "") 

    { 

      process.Kill();

    } 

}

void CopyPicToWord(string path1,string path2)

path1+="\\";//图像所在文件夹路径 

path2+="\\";//word所在文件夹路径 

DirectoryInfo dir = new DirectoryInfo(path1); 

DirectoryInfo dir1 = new DirectoryInfo(path2); 

string picName = "", name = "", docName = ""; 

int index = 0; string picPath = "", docPath = ""; 

int num = 1; 

foreach (FileInfo d in dir.GetFiles("*.jpg")) 

     int count = (dir.GetFiles("*.jpg")).Count(); 

     num++; 

     picName = d.Name; 

     index = picName.LastIndexOf("."); 

     if (picName.Substring(index + 1) == "jpg") 

     { 

name = picName.Substring(0, index);

 docName = name + ".doc"; 

FileInfo d2 = new FileInfo(docName); 

if (d2.Exists)

 { 

picPath = path1 + picName; 

docPath = path2 + docName; 

wordManager.CreateNewDocument(docPath); 

wordManager.InsertPicture("picture2", picPath, picWith, picHight, 2); 

wordManager.SaveDocument(docPath); //文档路径 

}

        } 

wordManager.killWinWordProcess();

}

基于径向基函数神经网络RBFNN的自适应滑模控制学习(Matlab代码实现)内容概要:本文介绍了基于径向基函数神经网络(RBFNN)的自适应滑模控制方法,提供了相应的Matlab代码实现。该方法结合了RBF神经网络的非线性逼近能力和滑模控制的强鲁棒性,用于解决复杂系统的控制问题,尤其适用于存在不确定性和外部干扰的动态系统。文中详细阐述了控制算法的设计思路、RBFNN的结构与权重更新机制、滑模面的构建以及自适应律的推导过程,通过Matlab仿真验证了所提方法的有效性和稳定性。此外,文档还列举了大量相关的科研方向和技术应用,涵盖智能优化算法、机器学习、电力系统、路径规划等多个领域,展示了该技术的广泛应用前景。; 适合人群:具备定自动控制理论基础和Matlab编程能力的研究生、科研人员及工程技术人员,特别是从事智能控制、非线性系统控制及相关领域的研究人员; 使用场景及目标:①学习和掌握RBF神经网络与滑模控制相结合的自适应控制策略设计方法;②应用于电机控制、机器人轨迹跟踪、电力电子系统等存在模型不确定性或外界扰动的实际控制系统中,提升控制精度与鲁棒性; 阅读建议:建议读者结合提供的Matlab代码进行仿真实践,深入理解算法实现细节,同时可参考文中提及的相关技术方向拓展研究思路,注重理论分析与仿真验证相结合。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值