Tag: openxml

将单元格的DataType更改为Double

我正在使用OpenXML创建Microsoft Excel文件。 我正在尝试将双类型变量(例如:4.987456789)插入到Excel中 Cell cell = new Cell() { CellReference = “A2”, DataType = CellValues.String, CellValue = new CellValue(Convert.ToString(value)) }; 但是,当制作单元格时,它是文本forms,Excel表示“此单元格中的数字格式为文本或前面有撇号”。 如何格式化单元格插入双? 编辑:对不起,这是双倍的? 键入,我按照本教程

OpenXML替换word文档的特定customxml部分

我正在使用OpenXML SDK ver 2来操作一些word文档。 文档目前有自定义的xml部分,我想要做的是具体替换部件的xml。 我知道我可以做这样的事情来访问文档的customxml部分: Dim mainStream As New MemoryStream() Dim buffer As Byte() = File.ReadAllBytes(Server.MapPath(“myfile.docx”)) mainStream.Write(buffer, 0, buffer.Length) Try Using mainDocument As WordprocessingDocument = WordprocessingDocument.Open(mainStream, True) MainDocumentPart mainPart = mainDocument.MainDocumentPart; ‘collection of custom xml parts Dim parts = mainPart.CustomXmlParts For Each part As CustomXmlPart In parts ‘how do I replace the xml here?? […]

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

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

EPPlus数据透视表 – 折叠整个字段

有谁知道如何做到这一点? 我在.Net中使用EPPlus并创建了一个包含2个行字段和一个摘要数据字段的数据透视表: Dim Pivot As OfficeOpenXml.Table.PivotTable.ExcelPivotTable Pivot = wksPivot.PivotTables.Add(wksPivot.Cells(“A1”), Datarange, “pName”) Pivot.RowFields.Add(Pivot.Fields(“Fld1”)).Sort = Table.PivotTable.eSortType.Ascending Pivot.RowFields.Add(Pivot.Fields(“Fld2”)).Sort = Table.PivotTable.eSortType.Ascending Dim dtaFld As OfficeOpenXml.Table.PivotTable.ExcelPivotTableDataField dtaFld = Pivot.DataFields.Add(Pivot.Fields(“XYZ”)) dtaFld.Function = Table.PivotTable.DataFieldFunctions.Sum 一切都很好,但我希望在用户打开工作簿时将数据透视表开始折叠(在Excel中,当您创建数据透视表时,可以右键单击数据元素并选择“展开/折叠” “>”折叠整个字段“ 我可以通过代码来做到这一点吗? (如果EPPlus不支持这个,我愿意使用直接的OpenXML ……) 还有,有没有办法从工作簿中删除原始数据,以便数据透视表仍然有效? 我试过,当我打开工作簿时,我的数据透视表是空白的? – 我现在的逻辑让我想到了这个问题 ……有什么想法? (我知道我在VB中写过这个问题。但我在这个问题上添加了C#和VB标签 – 我对任何一种语言的代码感到满意 – 谢谢!!)

使用带有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 […]

如何使用c#读取xls和xlsx文件

如何使用带有OpenXML格式的 c#读取xls和xlsx文件而不使用OLEDB连接 。 我正在寻找Open XML格式的程序。 下面是我使用OLEDB预处理的代码。 但我正在寻找OpenXML格式。 public static DataTable ConvretExcelToDataTable(string FilePath) { string strConn = string.Empty; if (FilePath.Trim().EndsWith(“.xlsx”)) { strConn = string.Format(“Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\”Excel 12.0 Xml;HDR=YES;IMEX=1\”;”, FilePath); } else if (FilePath.Trim().EndsWith(“.xls”)) { strConn = string.Format(“Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\”Excel 8.0;HDR=Yes;IMEX=1\”;”, FilePath); } OleDbConnection conn = null; OleDbCommand cmd = null; OleDbDataAdapter da = null; DataTable dt […]

使用c#突出显示Docx中的文本

我需要在docx文件中突出显示一个句子,我有这个代码,并且它适用于许多文档,但是我注意到对于某些文档,文档中的文本是逐字设置的,而不是整个句子,我的意思是每个单词都带有它自己的Run,所以在搜索那个句子时,找不到它,因为它在docx中逐字逐句。 注意:我正在使用阿拉伯语文本。 private void HighLightText_userSentence(Paragraph paragraph, string text, string title, string author, decimal percentage, string _color) { string textOfRun = string.Empty; var runCollection = paragraph.Descendants(); Run runAfter = null; //find the run part which contains the characters foreach (Run run in runCollection) { if (run.GetFirstChild() != null) { textOfRun = run.GetFirstChild().Text.Trim(); if (textOfRun.Contains(text)) { //remove […]

如何在打开的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 = […]