我正在尝试使用Interop.Word.Application打开.docx文件并转换为PDF.它作为控制台应用程序,但如果我在我的Web应用程序中使用它不起作用.我试图看到该文件夹的权限.我给了'网络服务'完全控制,但我仍然没有设置对象引用word.Documents.Open.你能告诉我可能出现什么问题吗?我遇到了这个错误.请告诉我.我很感激任何建议.谢谢.
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
object oMissing = System.Reflection.Missing.Value;
word.Visible = false;
word.ScreenUpdating = false;
string fileName = @"c:\OUTPUT\test.docx");
Document doc = word.Documents.Open(filename, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
doc.Activate();
Run Code Online (Sandbox Code Playgroud) 我有一个"模板"docx文档,其中包含所需的布局,并希望使用C#插入内容,但我找不到一种方法来唯一地处理文档的特定部分,如段落或表格.唯一标识文档中元素的最佳方法是什么?谢谢,Matt Sharpe.
使用OpenXML SDK,2.0 CTP,我试图以编程方式创建一个Word文档.在我的文档中,我必须插入项目符号列表,列表中的一些元素必须加下划线.我怎样才能做到这一点?
我很好奇现在有多少人在封闭和商业环境中使用Open XML(OOXML)(纯粹的或通过SDK).我很清楚"公共网络"(MSDN,OpenXMLDeveloper.org等)上发生了什么,但我想知道SO人们对它的体验,包括好的和坏的.
大多数人选择退出VBA和VSTO而不是直接使用OOXML格式吗?您从OOXML获得的好处是您从对象模型中获得的好处.我想更多地了解你为什么使用它或为什么不使用它,你用它做什么等等.
我只是试图从社区中获得OOXML作为文档自动化或其他用途的方法.我没有找到社区论坛(这一个或其他人)对问题和用户非常活跃(通过这篇文章的标签查看问题的数量),所以我想知道我是否是极少数人之一正在广泛使用OOXML.
我希望将Office 2007/2010/2013文档遵守的所有XML模式集中在一起.我从ISO/IEC 29500:2012规范和ECMA-376规范中找到了一个数字.我还在w3.org上找到了一些(例如xmldsig#).但我一直无法找到其中的大多数(例如模式http://schemas.openxmlformats.org/spreadsheetml/2006/main).
搜索microsoft.com上仅产生像网页这样,似乎有此内容.但是,大多数这些模式都是<xs:imports>我无法找到的文件.
有没有其他人有幸找到这些文件?
是否可以使用OpenXML SDK创建和编辑Excel文档而无需创建本地文件?
根据文档,该Create方法需要a filepath,它创建文件的本地副本.
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook);
Run Code Online (Sandbox Code Playgroud)
我在这里引用MSDN文章:https: //msdn.microsoft.com/en-us/library/office/ff478153.aspx
我的要求是创建文件,浏览器应该点击按钮下载.
有什么建议吗?
我使用OpenXml SDK 2.0创建了一个Excel文档,现在我必须设置它的样式,但我不能.
我不知道如何绘制背景颜色或更改不同单元格中的字体大小.
我创建单元格的代码是:
private static Cell CreateTextCell(string header, string text, UInt32Value index)
{
Cell c = new Cell();
c.DataType = CellValues.InlineString;
c.CellReference = header + index;
InlineString inlineString = new InlineString();
DocumentFormat.OpenXml.Spreadsheet.Text t = new DocumentFormat.OpenXml.Spreadsheet.Text();
t.Text = text;
inlineString.AppendChild(t);
c.AppendChild(inlineString);
return c;
}
Run Code Online (Sandbox Code Playgroud) 我需要使用Open XML SDK 2.0从Excel 2007工作簿中的单个工作表中读取数据.我花了很多时间来搜索这样做的基本指导,但我只是在创建电子表格方面找到了帮助.
如何使用此SDK迭代工作表中的行,然后迭代每行中的单元格?
我有一个Excel 2010电子表格,其中包含3个名为Sheet1,Sheet2和Sheet3的工作表.
我正在尝试按名称获取对工作表的引用.
我正在使用代码:
using (SpreadsheetDocument myWorkbook = SpreadsheetDocument.Open(FileName, true))
{
//Access the main Workbook part, which contains all references
WorkbookPart workbookPart = myWorkbook.WorkbookPart;
WorksheetPart worksheetPart = workbookPart.WorksheetParts.Last();
// this gives me Sheet1
SheetData sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>();
}
Run Code Online (Sandbox Code Playgroud)
我试图获得Sheet2的引用,但我找不到这样做的方法.
我越走越近了,但我还没到那里:
var x = workbookPart.Workbook.Sheets.Where(s=> s.GetAttribute("name", "").Value == "Sheet2").FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
这让我得到了工作表的参考,但没有给工作表上的数据
谢谢
使用c#处理Open XML 2.0以解析大型Excel文件.问题我遇到的是我正在解析的单元格没有DataType I然后检查NumberFormatId以确定它是十进制,数字还是日期.我正在寻找数字/小数与日期的确切NumberFormatId范围.他们似乎到处都是一些数字/小数的格式为189,212,214,305,日期的值为185,194,278等.有谁知道规范是否定义了这些范围?
编辑 - 更多信息
下面是xl文件夹中style.xml文件的数字格式194的示例.
excel表来自世界不同地区,所以我认为数字格式不同,但它们是否重叠?numFmtId 194将不同于不同文化设置的日期吗?
下面是我如何将像"40574"这样的c.CellValues转换为日期,但问题是如何知道"40574"是日期而不是数字?
DateTime.FromOADate(Convert.ToDouble(c.CellValue.Text));
Run Code Online (Sandbox Code Playgroud)
目前我通过检查是否没有DataType而不是检查CellFormat来做这个,但是当我的检查中没有一些NumberFormatId时会出现问题.
private Object FormatCellValue(Cell c, SharedStringTable ssTable, CellFormats cellFormats)
{
if (c.CellValue != null)
{
// If there is no data type, this must be a string that has been formatted as a number
if (c.DataType == null)
{
CellFormat cf;
if (c.StyleIndex == null)
{
cf = cellFormats.Descendants<CellFormat>().ElementAt<CellFormat>(0);
}
else
{
cf = cellFormats.Descendants<CellFormat>().ElementAt<CellFormat>(Convert.ToInt32(c.StyleIndex.Value));
}
if ((cf.NumberFormatId >= 14 && cf.NumberFormatId <= 22) ||
(cf.NumberFormatId >= 165 …Run Code Online (Sandbox Code Playgroud) openxml ×10
c# ×6
excel ×3
openxml-sdk ×3
docx ×2
ms-word ×2
asp.net ×1
asp.net-4.0 ×1
bulletedlist ×1
excel-2010 ×1
ms-office ×1
xsd ×1