我们需要将所有MS Office文档转换为PDF,TIFF或任何类似的图像格式,而不会丢失格式(这些是无法篡改的官方文档).
如果没有在可以执行此操作的计算机上安装Office,有没有办法做到这一点?理想情况下,这将在服务器上运行并运行多线程,而无需Office Automation的开销.
所以我需要编辑Word文档中的一些文本.我创建了一个Word文档并将其保存为XML.它保存正确(我可以在MS Word中打开XML文件,它看起来与docx原始文件完全一样).
那么我使用PHP DOM编辑文件中的一些文本(只有两行)(EDIT - bellow已经修复了工作版本):
<?php
$firstName = 'Richard';
$lastName = 'Knop';
$xml = file_get_contents('template.xml');
$doc = new DOMDocument();
$doc->loadXML($xml);
$doc->preserveWhiteSpace = false;
$wts = $doc->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 't');
$c1 = 0; $c2 = 0;
foreach ($wts as $wt) {
if (1 === $c1) {
$wt->nodeValue .= ' ' . $firstName;
$c1++;
}
if (1 === $c2) {
$wt->nodeValue .= ' ' . $lastName;
$c2++;
}
if ('First Name' === substr($wt->nodeValue, 0, 10)) {
$c1++;
}
if ('Last Name' === substr($wt->nodeValue, …Run Code Online (Sandbox Code Playgroud) 将向用户显示扩展名为 *.docm 的模板报告,用户将对其进行修改,然后单击“保存”按钮。我想将修改后的文档作为accessionID.docm写入指定的文件夹中。FileFormat = 对象必须是什么?
private void btnSaveDocument_Click(object sender, EventArgs e)
{
if (m_docFileName == ReportWrite.m_templateReport)
{
m_docFileName = ReportWrite.m_accessionId.ToString();
object FileName = RIS_CLIENT.Properties.Settings.Default.DownloadPath + "\\" + m_docFileName;
object FileFormat = Word.WdSaveFormat.wdFormatRTF;
object LockComments = false;
object AddToRecentFiles = false;
object ReadOnlyRecommended = false;
object EmbedTrueTypeFonts = false;
object SaveNativePictureFormat = true;
object SaveFormsData = false;
object SaveAsAOCELetter = false;
object missing = false;
objWinWordControl.document.SaveAs(
ref FileName,
ref FileFormat,
ref LockComments,
ref missing,
ref AddToRecentFiles,
ref missing,
ref ReadOnlyRecommended,
ref …Run Code Online (Sandbox Code Playgroud) 可以从这个新的Com对象($ ie)获取进程ID吗?
$ie=New-Object -comobject InternetExplorer.Application
$ie.visible=$true
$ie.Navigate("www.stackoverflow.com")
Run Code Online (Sandbox Code Playgroud) 一些搜索返回此结果:哪些进程正在运行托管代码以及哪个版本?
但是,我想知道是否有一种"更好"的方式,然后简单地迭代加载的模块?寻找字符串"mscorwks.dll"似乎有点古怪.通过MSDN上的Process Class读取似乎并没有指出一个明显的解决方案.
做出的假设
谢谢
是否有任何开源 sdk 可以在 ASP.Net 应用程序中使用以将任何办公文档转换为 pdf。(我特别需要将 DOCX 转换为 PDF,但也希望能够转换 Excel 和 powerpoint 文件)。
我知道我可以使用下面显示的代码使用 Office 自动化,但我不想使用 Office 自动化,因为不建议在非交互式应用程序中使用它KB257757
我发现Aspose有一个可用于此(付费解决方案)的组件,但我想知道是否有任何开源解决方案。
//reference: Microsoft.Office.Interop.Word.dll
//using Word = Microsoft.Office.Interop.Word;
public static void Convert(string documentFilePath, string outputPath)
{
var ap = new Word.Application {Visible = false};
var document = ap.Documents.Open(documentFilePath);
document.ExportAsFixedFormat(outputPath,
WdExportFormat.wdExportFormatPDF,
OptimizeFor: WdExportOptimizeFor.wdExportOptimizeForPrint,
BitmapMissingFonts: true, DocStructureTags: false);
document.Close();
}
Run Code Online (Sandbox Code Playgroud)
注意:我看到有些人建议为此使用 OpenXML。但是 OpenXML 不提供任何将 Office 文档转换为 PDF 文档的方法。
我从 COM 库(Microsoft Office Document Imaging 又名 MODI)收到一个 IPictureDisp 形式的图像,我想将其转换为 System.Drawing.Image 对象。
最好的方法是什么?
目前我正在使用下面的代码,但是它会抛出 NotImplementedException。
internal sealed class IPictureDispHost : AxHost
{
/// <summary>
/// Default Constructor, required by the framework.
/// </summary>
private IPictureDispHost() : base(string.Empty) { }
/// <summary>
/// Convert the image to an ipicturedisp.
/// </summary>
/// <param name="image">The image instance</param>
/// <returns>The picture dispatch object.</returns>
public new static object GetIPictureDispFromPicture(Image image)
{
return AxHost.GetIPictureDispFromPicture(image);
}
/// <summary>
/// Convert the dispatch interface into an image …Run Code Online (Sandbox Code Playgroud) 以下是基于VSTO的Word插件的代码(可读性简化版).
问题是,如果我打开了两个文档,例如文档和模板,我的插件有助于开发模板并正常工作,直到模板关闭并在同一个Word实例中重新打开(文档文件使Word保持活动状态).一旦发生这种情况,即使附加了侦听器(使用调试器确认),也不会收到SelectionChange事件.
这段代码有什么问题吗?附加选择更改事件的任何其他方式?
void Application_DocumentOpen(Word.Document Doc)
{
// this method gets called as intended
Document vstoDoc = Globals.Factory.GetVstoObject(doc);
vstoDoc.SelectionChange += new Microsoft.Office.Tools.Word.SelectionEventHandler(ThisDocument_SelectionChange);
}
private void Application_DocumentBeforeClose(Word.Document doc, ref bool Cancel)
{
// this one also gets called as intended
Document vstoDoc = Globals.Factory.GetVstoObject(doc);
vstoDoc.SelectionChange -= new Microsoft.Office.Tools.Word.SelectionEventHandler(ThisDocument_SelectionChange);
}
void ThisDocument_SelectionChange(object sender, SelectionEventArgs e)
{
// this doesn't get called if the document is closed and open again within the same Word instance
Log("Selection changed");
}
Run Code Online (Sandbox Code Playgroud)
更新:这似乎是VSTO的错误.
附加到其他事件工作正常,我可以使用ContentControlOnEnter/Exit:
vstoDoc.SelectionChange += ThisDocument_SelectionChange; …Run Code Online (Sandbox Code Playgroud) 我想从我的ASP.NET应用程序生成一个word文档.目前,我们展示了一个"议程清单",它是议程信息和所有项目/主题.此页面需要具有单词打开的功能.议程页面不是静态的,它是从SQL Server中提取的议程项目的动态列表.
关于最佳解决方案的任何建议?我正在寻找一个快速的解决方案,OpenXML似乎有点太耗时.我愿意购买第三方工具.
谢谢!