Tag: openxml

OpenXML将值写为string,并将值转换为数值时更改

我正在使用OpenXML将一些数据写入Excel。 我已经成功地将所有数据input到电子表格中,但是当我这样做的时候,它们都是以string格式。 这是因为我主要利用MSDN上提供的示例代码,并将它们作为InsertSharedStringItem ( string )插入到Excel中。 但是我find了两种将单元格转换为数字的方法。 第一个是一个简单的CellValues.Number而不是CellValues.SharedString但似乎改变了单元格中的所有实际值以及将其更改为一个数字。 一个例子是我现在有一个0,现在是5,11现在是0,21是33,这样的奇怪的东西(如果数字重复0,他们都改变,在0的情况下,5)。 显然这是行不通的。 然后我发现另一种方法在Excel中将string转换为数字,并在此处find(如果您单击该答案中的链接转到该用户源,则需要在URL中添加“www”)。 这个解决scheme的问题是,它会将所有的string转换为双精度值,但是这次的值与双精度格式的第一个解决scheme相同。 还值得注意的是,我的第三列应该是一个string,不需要转换为数字,但它反正。 这是我正在与: private static void WriteToExcel(string[] contents, char[] desiredColumns) { string filePath = @"D:\Folder\test.xlsx"; try { using (SpreadsheetDocument StatsCollection = SpreadsheetDocument.Open(filePath, true)) { string sheetName = ""; int totalRows = contents.Length / 15; int contentsIndex = 0; for (uint indexRow = 1; indexRow […]

在OpenXML中使用XML映射导入xml

我一直在尝试使用OpenXML SDK中的xml映射将XML数据导入Excel。 我find了使用Excel Interop做这个的多个例子,但是没有使用SDK。 作为一个侧面说明,我有这个工作的Word文件,但程序是不一样的Excel(Word中的CustomXmlPart,Excel中的CustomXmlMappingPart)。 也许这是不可能直接使用SDK的。 解决方法可能是使用命名范围,但我觉得不太实际。 编辑:场景使用带有XML映射的Excel文件(按照所述创buildhttps://support.office.com/zh-cn/article/Import-XML-data-6eca3906-d6c9-4f0d-b911- c736da817fa4?ui = en-US&rs = en-US&ad = US )作为“模板”来填充数据。 可以是客户名称,当前date或类似的。 我尝试过类似的东西。 与Word相比,映射显示在CustomXmlMappingsPart中。 using (var fileStream = File.Open(@"c:\temp\test.xslx", FileMode.Open)) { SpreadsheetDocument excelDoc = SpreadsheetDocument.Open(fileStream, true); // Only one mapping // When doing this for word, there is a document.MainDocumentPart.CustomXmlParts var mapping = excelDoc.WorkbookPart.GetPartsOfType<CustomXmlMappingsPart>().FirstOrDefault(); XNamespace mappingNS = "http://demoimport.org/xmlimport"; var xmlData […]

如何在MarkLogic中创build多页面excel

我想在单个工作簿中创build两张工作表的Excel文件。 当我尝试使用下面的代码时,它会创build一个无法打开的工作簿。 但是,当我创build一个单一的工作表。 请为这两种情况find附件代码,并让我知道我错过了什么。 创build单张excel(工作)。 declare namespace ms = "http://schemas.openxmlformats.org/spreadsheetml/2006/main" ; declare namespace ns2 = "http://www.example.com/"; declare function local:AgentReport() { <AgentReport> <Report> <GroupNumber>1</GroupNumber> <Quotes>1</Quotes> <Converted>1</Converted> <Conv_Rate>1</Conv_Rate> </Report> <Report> <GroupNumber>2</GroupNumber> <Quotes>2</Quotes> <Converted>2</Converted> <Conv_Rate>2</Conv_Rate> </Report> </AgentReport> }; declare function local:getRows( $x ) as element(ms:row)* { let $first-row := <ms:row> { for $i in $x/*/*[1]/child::element() return <ms:ct="inlineStr"> <ms:is> […]

使用OpenXML写入现有的Excel文件

任何人都可以告诉我我的代码中缺less什么? 它运行没有任何错误,但它不会写入我的Excel文件。 我只是试图把它写到我的电子表格的商业选项卡上的单元格A1。 我的代码如下: using System; using System.Data; using Microsoft.SqlServer.Dts.Runtime; using System.Windows.Forms; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.IO; using System.Reflection; using System.Data.OleDb; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet; using System.Xml; using System.Diagnostics; namespace Application.Model { [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute] public class TempCode : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase { string FilePath; string FileName; string FileExceptionsPath; string FileExceptionsName; string […]

我怎样才能得到一个Excel工作表的使用范围与OpenXML?

我需要在新的工作表中获取使用的单元格范围。 例如: A1:AY55 在Excel VBA中,可以通过恰当命名的UsedRange属性来获取。 OpenXML中是否有相同的内容?

c#openxml excel样式表边框错误

我正在制作一个带单元格边框的Excel工作表样式表,只要没有两个以上的边框,它就会工作。 但是,当我添加第三个边框时,excel告诉我打开它时xml出现错误,但只有当第三个边框具有右侧和左侧边框时。 当它只是一个顶部和底部的边界没有问题。 为什么只有边界索引2只有右边界和左边界时才会出现错误? 我将在下面放置我的样式表方法的完整代码,但是我遇到麻烦的具体部分在这里: //this is the border index 2 (third border) new DocumentFormat.OpenXml.Spreadsheet.Border( //error is caused by this section //if I leave the right and left border out there is no error //also no error if this whole border is border index 0 or 1 new DocumentFormat.OpenXml.Spreadsheet.RightBorder( new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true […]

如何使用openxml读取excel文件的单元格数据

我正在使用DocumentFormat.openxml nuget pkg读取.xlsx文件。 我试图读取date单元格[G2]和数据从[b5]到[m5] static void Main(string[] args) { string sFileTypeError = string.Empty; string myFilePath = @"C:\Landing\file.xlsx"; //string ext = Path.GetExtension(myFilePath); var fileName = Path.GetFileName(myFilePath); var fileExtension = Path.GetExtension(fileName); if ((fileExtension != ".xlsx") && (fileExtension != ".xls")) sFileTypeError = "Invalid file. \n\nPlease browse a correct Excel file to upload."; else { using (SpreadsheetDocument doc = […]

如何使用c#将xls文件转换为xlsx文件

我正在开发一个应用程序,从Excel文件读取数据。 但是当我尝试打开它时,如果以xls格式保存源文件(在使用OpenXML打开Excel工作表时文件包含损坏的数据错误),则会引发exception。 当我保存这个文件的xlsx格式,它工作正常。 请帮我解决这个问题。

Excel 2007中的数值与基础xml文件不一致的可视化

我正在尝试从Excel外部读取Excel 2007文件(xlsx),并发现我无法解释的不一致。 如果你input19.99的值到一个单元格中,然后看看底层的Xml文档,它实际上被存储为19.989999999999998。 这不是唯一的价值,但这是一个合理的例子。 没有格式应用在工作表中。 在我的例子中,我只是打开一个新的工作簿,在A1键入19.99,并保存该文件。 我试图在开放式办公室和Google文档中打开这个简单的例子,并且在文档加载时显示19.99。 我的问题是,如何确定何时将此值从19.989999999999998转换为19.99以供其他系统使用?

需要一个excel插件来查看底层的openxml

有谁知道一个Excel插件,可以告诉你底层的openxml(最好在实时和语法着色)? 我知道我可以重命名xlsx来压缩searchxml,但如果有人知道插件,简化,然后让我知道