Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel C#OpenXML:添加新行后,如何获取单元格在Excel中的位置(row row=new row());不使用excel Interpol或宏_C#_Excel_Openxml - Fatal编程技术网

Excel C#OpenXML:添加新行后,如何获取单元格在Excel中的位置(row row=new row());不使用excel Interpol或宏

Excel C#OpenXML:添加新行后,如何获取单元格在Excel中的位置(row row=new row());不使用excel Interpol或宏,c#,excel,openxml,C#,Excel,Openxml,我的问题是在不使用excel Interpol或宏的情况下获取单元格在excel中的位置。只有c#和OpenXML。像(A3)这样的位置。当您让您的单元格对象执行此操作以获取字符串“A1”时,例如: myCell.CellReference.Value 如果要通过单元格引用查找单元格,请执行以下操作: public static Cell getCellByReference(string cellReference, Worksheet ws) { return ws.Descend

我的问题是在不使用excel Interpol或宏的情况下获取单元格在excel中的位置。只有c#和OpenXML。像(A3)这样的位置。

当您让您的单元格对象执行此操作以获取字符串“A1”时,例如:

myCell.CellReference.Value
如果要通过单元格引用查找单元格,请执行以下操作:

public static Cell getCellByReference(string cellReference, Worksheet ws)
{
    return ws.Descendants<Cell>().Where(c => c.CellReference.Value == cellReference).FirstOrDefault();
}

Cell myCell = getCellByReference("A1", actualWorksheet)
公共静态单元格getCellByReference(字符串cellReference,工作表ws) { 返回ws.subjects().Where(c=>c.CellReference.Value==CellReference.FirstOrDefault(); } Cell myCell=getCellByReference(“A1”,实际工作表)
当您有单元格对象时,执行此操作以获取字符串“A1”,例如:

myCell.CellReference.Value
如果要通过单元格引用查找单元格,请执行以下操作:

public static Cell getCellByReference(string cellReference, Worksheet ws)
{
    return ws.Descendants<Cell>().Where(c => c.CellReference.Value == cellReference).FirstOrDefault();
}

Cell myCell = getCellByReference("A1", actualWorksheet)
公共静态单元格getCellByReference(字符串cellReference,工作表ws) { 返回ws.subjects().Where(c=>c.CellReference.Value==CellReference.FirstOrDefault(); } Cell myCell=getCellByReference(“A1”,实际工作表)
有一本很有帮助的电子书,叫做《那是很久以前写的》(2007?)。它解释了这个问题的许多复杂细节

这本电子书说有两种方法可以确定单元格的位置:使用CellRefernece属性或不使用CellReference属性

具有CellReference属性
CellRefence属性不能保证,就像上面的xml一样。如果CellReference不存在,则需要通过文件中数据的位置来确定位置。因此,第一行数据对应于电子表格的第一行。与一行中的单元格位置相同。

有一本很有帮助的电子书,名叫《那是很久以前写的》(2007?)。它解释了这个问题的许多复杂细节

这本电子书说有两种方法可以确定单元格的位置:使用CellRefernece属性或不使用CellReference属性

具有CellReference属性 CellRefence属性不能保证,就像上面的xml一样。如果CellReference不存在,则需要通过文件中数据的位置来确定位置。因此,第一行数据对应于电子表格的第一行。与行中的单元格位置相同。

行行=新行()行。追加(ConstructCell(“abc”,CellValue.SharedString);sheetdata.append(行);行行行=新行()行。追加(ConstructCell(“abc”,CellValue.SharedString);sheetdata.append(行);