700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 如何在word和pdf中插入文件

如何在word和pdf中插入文件

时间:2021-05-22 16:56:25

相关推荐

如何在word和pdf中插入文件

1. word中插入文件

Code

protectedboolBatchDocAndCsv(stringdocFile,stringcsvFile)

{

if(string.IsNullOrEmpty(docFile)||string.IsNullOrEmpty(csvFile))

{

returnfalse;

}

if(File.Exists(docFile)==false||File.Exists(csvFile)==false)

{

returnfalse;

}

WordClassobj=newWordClass();

obj.OpenDocument(docFile);

try

{

objectClassType="Package";

objectFileName=csvFile;

objectLinkToFile=true;

objectDisplayAsIcon=true;

objectIconFileName="C:\\WINDOWS\\system32\\packager.exe";

objectIconIndex=0;

objectIconLabel=csvFile;

objectwidth=100;

objectleft=0;

objecttop=0;

objectstart=0;

objectend=0;

objectrange=null;

objectfindText="EMBEDDED_CSV";

objectReplacement="";

objectForward=true;

objectWrap=Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;

objectFormat=false;

objectMatchCase=false;

objectMatchWholeWord=false;

objectMatchByte=false;

objectMatchAllWordForms=false;

objectMatchSoundsLike=false;

objectMatchWildcards=true;

obj.WordApplication.Selection.Find.ClearFormatting();

if(obj.WordApplication.Selection.Find.Execute(reffindText,refMatchCase,refMatchWholeWord,refMatchWildcards,

refMatchSoundsLike,refMatchAllWordForms,refForward,refWrap,refFormat,refReplacement,refmissing,refmissing,refmissing,refmissing,refmissing))

{

Thread.Sleep(1500);

obj.WordApplication.Selection.InlineShapes.AddOLEObject(refClassType,refFileName,refLinkToFile,refDisplayAsIcon,refIconFileName,refIconIndex,refIconLabel,refmissing);

}

else

{

obj.Close(false);

obj.Dispose();

returnfalse;

}

obj.Close(true);

obj.Dispose();

returntrue;

}

catch(Exceptionex)

{

obj.Close(false);

obj.Dispose();

returnfalse;

}

}

2.pdf中插入文件

需要用到Gnostice PDFtoolkit VCL

Code

protectedboolBatchPdfAndCsv(stringpdfFile,stringcsvFile)

{

if(string.IsNullOrEmpty(pdfFile)||string.IsNullOrEmpty(csvFile))

{

returnfalse;

}

if(File.Exists(pdfFile)==false||File.Exists(csvFile)==false)

{

returnfalse;

}

gtPDFDocumentXPDFDoc=newgtPDFDocumentXClass();

PDFDoc.LoadFromFile(pdfFile);

gtPDFFileAttachmentXFilAtt;

//CreatetheFileAttachmentObject

FilAtt=PDFDoc.CreatePDFFileAttachment();

//SettheFileAttachmentProperties.

stringAttachFile=csvFile;

FilAtt.FileName=AttachFile;

FilAtt.Author="";

FilAtt.Subject="";

FilAtt.Contents="";

FilAtt.IconColor=13;

FilAtt.FileAttachmentIcon=TxgtFileAttachmentIcon.faPushPin;

FilAtt.SetBounds(100,600,100,100);

//InserttheFileAttachment

PDFDoc.InsertFileAttachment(FilAtt,1);

PDFDoc.ShowSetupDialog=false;

PDFDoc.OpenAfterSave=true;

PDFDoc.SaveToFile(pdfFile);

returntrue;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。