有了EPPlus和OpenXML,有没有人知道如何计算行的语法?
说我的工作表叫做"工作表"
int numberRows = worksheet.rows.count()?要么worksheet.rows.dimension
我当然对答案感兴趣,但如何找到答案会很酷,比如"转到定义"并寻找这个或那个,等等.
我正在尝试打开Word文档,更改一些文本,然后将更改保存到新文档.我可以使用下面的代码完成第一项,但我无法弄清楚如何将更改保存到新文档(指定路径和文件名).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using DocumentFormat.OpenXml.Packaging;
using System.IO;
namespace WordTest
{
class Program
{
static void Main(string[] args)
{
string template = @"c:\data\hello.docx";
string documentText;
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(template, true))
{
using (StreamReader reader = new StreamReader(wordDoc.MainDocumentPart.GetStream()))
{
documentText = reader.ReadToEnd();
}
documentText = documentText.Replace("##Name##", "Paul");
documentText = documentText.Replace("##Make##", "Samsung");
using (StreamWriter writer = new StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create)))
{
writer.Write(documentText);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我是一个完全的初学者,请原谅基本问题!
我使用OpenXml创建Word文档,其中包含简单文本和本文下的一些表格.如何强制使用此文本的Paragraph始终显示在新页面上?也许这一段应该是一些标题,但我不知道该怎么做.
谢谢
打开OpenXML创建的电子表格时收到错误.错误如下.
Repaired Records: Cell information from /xl/worksheets/sheet.xml part
Repaired Records: Cell information from /xl/worksheets/sheet2.xml part
Repaired Records: Cell information from /xl/worksheets/sheet3.xml part
Run Code Online (Sandbox Code Playgroud)
我唯一能在网上找到有用的东西就是这个问题讨论了一种算法,它会多次改变单个单元格导致问题.话虽如此,我将把我的构造函数链接到SpreadsheetDocument以及更新单元格的三个函数(我曾经做过一次).
我可以根据需要提供任何其他功能,但我相信问题出现在下面列出的两个中.
顺便说说,
GetWorksheetPartByName
InsertCellInWorksheet
GetCell
Run Code Online (Sandbox Code Playgroud)
应该都按预期工作.
实际计划
static void Main(string[] args)
{
//Full path for File
const string newFile = "@C:\test.xlsx";
//Constructor creates default worksheet called "mySheet"
var spreadsheet = new XLSXHelper(newFile);
//updating some cells.
spreadsheet.UpdateCell("mySheet", "D2", "R", 2);
}
Run Code Online (Sandbox Code Playgroud)
构造函数
public XLSXHelper(string filepath)
{
newFile = filepath;
spreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook);
this.workbookPart = spreadsheetDocument.AddWorkbookPart();
workbookPart.Workbook = …Run Code Online (Sandbox Code Playgroud) 我正在使用OpenXML将图像插入到我的文档中.Microsoft提供的代码可以工作,但会使图像更小:
public static void InsertAPicture(string document, string fileName)
{
using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(document, true))
{
MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart;
ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
using (FileStream stream = new FileStream(fileName, FileMode.Open))
{
imagePart.FeedData(stream);
}
AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart));
}
}
private static void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId)
{
// Define the reference of the image.
var element =
new Drawing(
new DW.Inline(
new DW.Extent() { Cx = 990000L, Cy = 792000L },
new DW.EffectExtent()
{
LeftEdge = 0L,
TopEdge = 0L,
RightEdge …Run Code Online (Sandbox Code Playgroud) 我在其中一个单元格的xlsx文件中有一个格式为"4/5/2011"(月/日/年)的日期.我试图解析文件并在某些类中加载这些数据.
到目前为止,我解析单元格的部分如下所示:
string cellValue = cell.InnerText;
if (cell.DataType != null)
{
switch (cell.DataType.Value)
{
case CellValues.SharedString:
// get string from shared string table
cellValue = this.GetStringFromSharedStringTable(int.Parse(cellValue));
break;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望date可以是cell.DataType.事实是,在使用日期"4/5/2011"解析单元格时,cell.DataType的值为null,单元格的值为"40638",并且它不是共享字符串表的索引.(我之前尝试过这种方法,结果却出现了异常.)
有任何想法吗?谢谢
我需要以编程方式使用C#将几个预先存在的docx文件附加到一个长docx文件中 - 包括子弹和图像等特殊标记.页眉和页脚信息将被删除,因此这些信息不会导致任何问题.
我可以找到有关docx使用.NET Framework 3 操作单个文件的大量信息,但对于如何合并文件没有任何简单或明显的信息.还有一个第三方程序(Acronis.Words)可以做到这一点,但它非常昂贵.
已经建议通过Word进行自动化,但是我的代码将在IIS Web服务器上的ASP.NET上运行,因此对我而言,不能选择使用Word.很抱歉没有提到这一点.
继我在这里的最后一个问题
OpenXML看起来可能完全符合我的要求,但文档很糟糕.一个小时的谷歌搜索没有让我更接近找出我需要做什么.
我有一个word文档.我想以这样的方式将图像添加到该word文档(使用单词),然后我可以在OpenXML中打开文档并替换该图像.应该够简单,是吗?
我假设我应该能够将我的图像'占位符'赋予某种类型的ID,然后用它GetPartById来定位图像并替换它.这是正确的方法吗?这是什么ID?你如何使用Word添加它?
我能找到的每个远程类似的例子都是从ML开始构建整个word文档开始的,这真的没什么用处.
编辑:它发生在我身上,用新图像替换媒体文件夹中的图像会更容易,但再次找不到如何执行此操作的任何指示.
我一直在管理Subversion作为我公司的工程文档存储库.它工作得很好,但我对Subversion如何(应该)处理MS Office 2007格式有疑问.
我正在查看我的工作副本中的Excel 2007电子表格(扩展名.xlsx),Subversion已经应用了svn:mime-type属性application/octet-stream.这意味着Subversion被视为二进制,对吧?
我希望Subversion可以有效地存储新的MS Office文档格式.我的理解是,每次提交该文件时都会生成二进制文件的完整副本,而如果该文件是文本,则对该文件进行少量更改将导致将少量其他数据添加到存储库中(在至少是典型的情况).
我不太了解XML的细节,但我认为XML文件是文本,因此Subversion会有效地存储它.
是否可以配置Subversion以便有效地存储MS Office OpenXML文档?
后续工作(2009-11-09):我发现Office文档可以使用Office 2003 XML文档格式存储为纯文本(Excel:XML Spreadsheet 2003 ; Word:Word XML Document.有关于丢失的警告格式化,但我还没有遇到任何明显的格式丢失.
如何通过OpenXml更改文档的字体系列?我尝试了一些方法但是,当我打开文档时,它总是在Calibri中
按照我的代码,我尝试了.
我认为Header Builder无用于发布
private static void BuildDocument(string fileName, List<string> 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 = 0; i < lista.Count; i++)
{
Text t = new Text();
t.Text = lista[i];
if (t.Text == " ")
{
r.Append(new CarriageReturn());
}
else
{ …Run Code Online (Sandbox Code Playgroud)