Tag: openxml sdk

如何更改字体打开xml

如何通过OpenXml更改文档的字体系列? 我尝试了一些方法但是,当我打开文档时,它总是在Calibri中 按照我的代码,我尝试了。 我认为Header Builder无用于发布 private static void BuildDocument(string fileName, List lista, string tipo) { using (var w = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document)) { var mp = w.AddMainDocumentPart(); var d = new DocumentFormat.OpenXml.Wordprocessing.Document(); var b = new Body(); var p = new DocumentFormat.OpenXml.Wordprocessing.Paragraph(); var r = new Run(); // Get and format the text. for (int i […]

将 / Embed转换为aw:drawing

我有一个V:Shape我假设的V:Shape来自.Doc文件转换为.Docx文件,但在我编写的代码中,我想要一个DocumentFormat.OpenXml.Drawing.Pictures.Picture 。 有没有办法以编程方式转换为Picture ? 我正在使用的片段是: foreach (var item in value) { if (!item.Descendants().Any()) //pictures are processed differently – they’re an absolute s**t storm to code… { p.Append(item.CloneNode(true)); } else { p.Append(CreateImageRun(source, item, target, f)); } } public Run CreateImageRun(WordprocessingDocument sourceDoc, Run sourceRun, WordprocessingDocument target, FooterPart footerPart) { ImagePart newPart = footerPart.AddImagePart(ImagePartType.Png); ImageData shape = sourceRun.Descendants().FirstOrDefault(); […]

导出到Excel中的yyyy-MM-dd日期格式

有没有办法在Export to Excel函数中使用此方法从UniversalSortableDateTimePattern单独获取日期。 Excel不接受日期格式.. 我需要显示为yyyy-MM-dd。 任何建议都会有所帮助吗? 我的代码为 dtASalesDrivers.Columns.Add(new System.Data.DataColumn(“Start Date”, typeof(String))); DateTime dt = Convert.ToDateTime(txtATrendStartDate.Text); drASalesDrivers[2] = string.Format(“{0:yyyy-MM-dd}”, dt); dtASalesDrivers.Rows.Add(drASalesDrivers); 编辑: DateTime dt = Convert.ToDateTime(txtATrendStartDate.Text); drASalesDrivers[2] = string.Format(“{0:u}”, dt); 这会显示日期和时间。 有没有办法只显示日期???

使用OpenXML将PowerPoint演示文稿另存为PDF

我的目标是建立一个自动服务器端进程,将.ppt转换为.pdf 。 微软自己建议我使用OpenXML,现在我正在考虑这个问题。 我的问题是: 我可以使用OpenXML实际实现我的目标吗? 我很难找到我期望的方法,例如“另存为” 或许我只是误解了一切是如何运作的?

使用带有c#和ASP.net的openXML在powerpoint中创建动态表

我已经使用了这些链接并得到了一个工作代码,我可以使用模板报告(包含placeolders)并使用从数据库获取的数据生成新的PPTX报告。 我有4个占位符,我需要填充4个不同的数据表。 目前我正在使用该模板创建新的幻灯片并替换文本的占位符,但对于我无法弄清楚的表格。 我可以使用下面的代码生成表,但不能在占位符的位置生成表。 表始终显示在屏幕中央。 使用的链接: https : //blogs.msdn.microsoft.com/brian_jones/2008/11/18/creating-a-presentation-report-based-on-data/ https://code.msdn.microsoft.com/office/How-to-add-a-table-with-03578dde 从某个按钮点击事件中调用此信息: using (PresentationDocument presentationDocument = PresentationDocument.Open(slideName, true)) { //Get the first slide from presentation SlidePart intitalSlide = presentationDocument.PresentationPart.SlideParts.First(); AddNewSlide(presentationDocument, intitalSlide, 1045); } private void AddNewSlide(PresentationDocument presentationDocument, SlidePart _slideTemplate, int projectID) { PresentationPart parent = presentationDocument.PresentationPart; System.Data.DataTable dt = GetValueForPPTReport(projectID); var newSlidePart = parent.AddNewPart(“newSlide1”); //copy the […]

如何在打开的xml文档上保留样式

我使用开放XML(Microsoft Word – .docx)作为文件模板来自动生成其他文档。 在模板文档中,我定义了内容控件,并且我编写了代码来替换这些内容控件中的内容。 内容被替换并生成文档,但我正在努力保持风格。 在Word中,当检查内容控件的属性时,我检查了checbox“使用样式将文本格式化为空控件:样式”,并检查“在编辑内容时删除内容控件”。 当代码生成文档时,这似乎没有任何影响。 这是我的代码(这里的社区成员非常友好地帮助)来替换内容控件中的数据。 任何想法,我应该做什么,以保持格式? 格式化是简单的文本格式,如大小和字体。 请指教: private static void ReplaceTags(MainDocumentPart mainPart, string tagName, string tagValue) { //grab all the tag fields var tagFields = mainPart.Document.Body.Descendants().Where (r => r.SdtProperties.GetFirstChild().Val == tagName); foreach (var field in tagFields) { //remove all paragraphs from the content block field.SdtContentBlock.RemoveAllChildren(); //create a new paragraph containing […]

如何使用MS Open XML SDK从.pptx文件中检索图像?

我开始尝试使用Open XML SDK 2.0 for Microsoft Office 。 我现在能够做某些事情,例如检索每张幻灯片中的所有文本,并获得演示文稿的大小。 例如,我这样做: using (var doc = PresentationDocument.Open(pptx_filename, false)) { var presentation = doc.PresentationPart.Presentation; Debug.Print(“width: ” + (presentation.SlideSize.Cx / 9525.0).ToString()); Debug.Print(“height: ” + (presentation.SlideSize.Cy / 9525.0).ToString()); } 现在我想在给定的幻灯片中检索嵌入的图像。 有谁知道如何做到这一点或者可以指向我关于这个主题的一些文档?

C#OPEN XML:从EXCEL获取数据到DATATABLE时,跳过空单元格

任务 将数据从excel导入DataTable 问题 将跳过不包含任何数据的单元格,并将具有该行中数据的下一个单元格用作空列的值。 例如 A1为空A2具有值Tom然后在导入数据A1获得A2的值并且A2保持为空 为了说清楚,我在下面提供一些屏幕截图 这是excel数据 这是从excel导入数据后的DataTable 码 public class ImportExcelOpenXml { public static DataTable Fill_dataTable(string fileName) { DataTable dt = new DataTable(); using (SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Open(fileName, false)) { WorkbookPart workbookPart = spreadSheetDocument.WorkbookPart; IEnumerable sheets = spreadSheetDocument.WorkbookPart.Workbook.GetFirstChild().Elements(); string relationshipId = sheets.First().Id.Value; WorksheetPart worksheetPart = (WorksheetPart)spreadSheetDocument.WorkbookPart.GetPartById(relationshipId); Worksheet workSheet = worksheetPart.Worksheet; SheetData sheetData = […]

我将如何使用下面的DocumentFormat.OpenXml -details从docx文件中提取数据

我有一个通过添加xml架构创建的Docx文件。 我给你docx文件的链接。 现在我想提取 – To,From,heading,body。 目前我正在使用Library DocumentFormat.OpemXml。 但没有成功。 可以任何人建议我的步骤。

如何使用OpenXML SDK通过应用格式(格式化单元格值)获取单元格值

我一直在谷歌搜索并在网站上搜索答案,但我找不到解决方案 – 各地人们大多讨论如何在文档中添加新的数字格式并应用它。 我需要的是将单元格值作为带有应用格式的字符串 – 即与Excel显示的字符串相同。 我已经认为没有简单的方法或内置函数可以返回单元格的现成格式化值。 所以在我看来,要获得我需要做两件事的价值:1。获取格式字符串。 2.使用此字符串格式化单元格值。 但是这两个步骤都有问题。 可以轻松获取包含NumberFormatId的CellFormat实例: CellFormat cellFormat = (CellFormat) document.WorkbookPart.WorkbookStylesPart.Stylesheet.CellFormats.ElementAt(cell.StyleIndex); 但是,如果id对应于标准预定义格式之一,如何使用此NumberFormatId获取格式字符串? (即低于160)它们不在电子表格文档中,我无法相信它们应该在应用程序中进行硬编码。 此外,一旦获得格式字符串,如何将其应用于单元格值? 到目前为止我理解,代码应该检查单元格值的类型,如果是数字 – 使用格式字符串将其转换为字符串。 我发现这个页面提到了使用Microsoft.Office.Excel.Interop,但我更愿意继续使用OpenXML SDK。 总的来说,我很惊讶在Web上找到这个问题的确切答案是如此困难,因为我认为这将是许多开发人员在日常工作中需要的东西。