本文整理汇总了C#中IWorkbook.GetSheetIndex方法的典型用法代码示例。如果您正苦于以下问题:C# IWorkbook.GetSheetIndex方法的具体用法?C# IWorkbook.GetSheetIndex怎么用?C# IWorkbook.GetSheetIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWorkbook
的用法示例。
在下文中一共展示了IWorkbook.GetSheetIndex方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteDataToSheet
private static Int32 WriteDataToSheet(Object data, ref IWorkbook wBook, String sheetName, Int32 startColumn, Int32 startRow, out Int32 maxRow)
{
Int32 result = 0; // row affected
Int32 currentRow = startRow;
Int32 currentColumn = startColumn;
maxRow = 0;
// check whether the sheet is already exis or not
if (data != null && wBook != null && !String.IsNullOrWhiteSpace(sheetName))
{
if (wBook.GetSheetIndex(sheetName) < 0)
wBook.CreateSheet(sheetName);
ISheet sheet = wBook.GetSheet(sheetName);
if (sheet != null)
{
if (data.GetType().GetMethod("GetEnumerator") != null )
{
IEnumerator enumerator = (IEnumerator) data.GetType().GetMethod("GetEnumerator").Invoke(data, null);
Int32 count = (Int32) data.GetType().GetProperty("Count").GetValue(data);
Int32 i = 0;
while (enumerator.MoveNext())
{
currentColumn = WriteDataToSheet(enumerator.Current, ref wBook, sheetName, currentColumn, currentRow, out currentRow);
if (i < count - 1)
{
currentRow++;
currentColumn = startColumn;
}
if (currentRow > maxRow)
maxRow = currentRow;
else
currentRow = maxRow;
i++;
}
}
else
{
PropertyInfo [] propInfos = data.GetType().GetProperties();
if (propInfos != null && propInfos.Count() > 0)
{
foreach (var propInfo in propInfos)
{
ColumnName colNameAttribute = propInfo.GetCustomAttribute<ColumnName>(true);
Skipped skippedAttribute = propInfo.GetCustomAttribute<Skipped>(true);
String fieldFormat = (propInfo.GetCustomAttribute<DateFormat>(true) != null) ? propInfo.GetCustomAttribute<DateFormat>(true).Format : "";
String columnName = "";
String fieldName = propInfo.Name;
Type fieldType = propInfo.PropertyType;
Object fieldValue = propInfo.GetValue(data);
if (skippedAttribute == null || (skippedAttribute != null && !skippedAttribute.IsSkipped(sheetName)))
{
if (!SystemTypes.Contains(fieldType) && !fieldType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
{
Int32 curMaxRow = 0;
currentColumn = WriteDataToSheet(fieldValue, ref wBook, sheetName, currentColumn, currentRow, out curMaxRow);
if (curMaxRow > maxRow)
maxRow = curMaxRow;
}
else
{
// Get Attributes[
if (colNameAttribute != null)
columnName = colNameAttribute.Name;
else
columnName = propInfo.Name;
// write header if this is the first row
if (currentRow == 0)
WriteToCell(ref sheet, currentRow, currentColumn, columnName);
// write the data
if (currentRow == 0)
WriteToCell(ref sheet, currentRow + 1, currentColumn, fieldValue, fieldFormat);
else
WriteToCell(ref sheet, currentRow, currentColumn, fieldValue, fieldFormat);
currentColumn++;
}
}
}
// add current row
if (currentRow == 0)
currentRow = 1; // we must write header and the first data row
if (currentRow > maxRow)
maxRow = currentRow;
//.........这里部分代码省略.........
示例2: GetUniqueSheetName
/**
* Generate a valid sheet name based on the existing one. Used when cloning sheets.
*
* @param srcName the original sheet name to
* @return clone sheet name
*/
public static String GetUniqueSheetName(IWorkbook wb, String srcName)
{
if (wb.GetSheetIndex(srcName) == -1)
{
return srcName;
}
int uniqueIndex = 2;
String baseName = srcName;
int bracketPos = srcName.LastIndexOf('(');
if (bracketPos > 0 && srcName.EndsWith(")"))
{
String suffix = srcName.Substring(bracketPos + 1, srcName.Length - bracketPos - 2);
try
{
uniqueIndex = Int32.Parse(suffix.Trim());
uniqueIndex++;
baseName = srcName.Substring(0, bracketPos).Trim();
}
catch (FormatException)
{
// contents of brackets not numeric
}
}
while (true)
{
// Try and find the next sheet name that is unique
String index = (uniqueIndex++).ToString();
String name;
if (baseName.Length + index.Length + 2 < 31)
{
name = baseName + " (" + index + ")";
}
else
{
name = baseName.Substring(0, 31 - index.Length - 2) + "(" + index + ")";
}
//If the sheet name is unique, then Set it otherwise Move on to the next number.
if (wb.GetSheetIndex(name) == -1)
{
return name;
}
}
}
示例3: GetMainSheetIndex
protected virtual int GetMainSheetIndex(IWorkbook workbook)
{
return workbook.GetSheetIndex(MainSheet);
}