本文整理汇总了C#中ClosedXML.Excel.XLWorkbook.TryGetWorksheet方法的典型用法代码示例。如果您正苦于以下问题:C# XLWorkbook.TryGetWorksheet方法的具体用法?C# XLWorkbook.TryGetWorksheet怎么用?C# XLWorkbook.TryGetWorksheet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClosedXML.Excel.XLWorkbook
的用法示例。
在下文中一共展示了XLWorkbook.TryGetWorksheet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getPointsFromFile
/// <summary>
/// Gets pointArray from file from specified path
/// </summary>
/// <returns></returns>
private int[,] getPointsFromFile()
{
if (Properties.Settings.Default.PathToTemplate.Equals(""))
{
MessageBox.Show("Please select a template in settings", "Failed to read points");
return null;
}
int[,] pointsArray = new int[41, 41];
try
{
var workbook = new XLWorkbook(Properties.Settings.Default.PathToTemplate);
IXLWorksheet worksheet;
if (!workbook.TryGetWorksheet("Points", out worksheet))
{
MessageBox.Show("Worksheet 'Points' not found in template", "Failed to read points");
return null;
}
for (int i = 3; i < 41; i++)
{
for (int j = 2; j < 39; j++)
{
var value = worksheet.Cell(i, j).Value.ToString();
if (value.Equals(""))
{
break;
}
if (!int.TryParse(worksheet.Cell(i, j).Value.ToString(), out pointsArray[-2 + i, 42 - j]))
{
MessageBox.Show("Error reading points" + i + " " + j);
break;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Failed to read points");
return null;
}
return pointsArray;
}