我是使用EPPlus的新手。使用EPPlus来转换Excel单元格的位置
我想要一个单元格,相对于一个起点,实现这个目标的最佳方法是什么?
E.g:
var startLocation = "C5";
var newLocation1 = TLoc(startLocation, 2, 3); //E8
var newLocation2 = TLoc(startLocation, 0, 1); //C6
现在我写这个方法我自己,因为我不熟悉EPPlus功能:
/// <summary>
/// Use EPPlus to translate the Location.
/// </summary>
/// <param name="startLocation"></param>
/// <param name="columns"></param>
/// <param name="rows"></param>
/// <returns></returns>
private string TLoc(string startLocation, int columns, int rows)
{
using (ExcelPackage tmpPack = new ExcelPackage())
{
var tmpWs = tmpPack.Workbook.Worksheets.Add("temp");
var startCell = tmpWs.Cells[startLocation];
int startColumn = startCell.Start.Column;
int startRow = startCell.Start.Row;
int tColumn = startColumn + columns;
int tRow = startRow + rows;
ExcelAddress translatedAddress = new ExcelAddress(tRow, tColumn, tRow, tColumn);
return translatedAddress.ToString();
}
}
请告诉我一个例子或链接我的文档。谢谢!
更具体一些:使用EPPlus来实现此功能的示例。
我喜欢在可用时使用成熟的技术,而不用冒着引入新bug的风险。
谢谢你的回答。但我正在尝试使用EPPlus软件包。 –
以上的答案不仅适用于EPPLus,您可以使用任何你喜欢的东西... –
以上的答案不仅适用于EPPLus,你可以使用任何你喜欢的东西,一般它会为你提供excel地址的转换。 –