本文整理汇总了C#中ISheet.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# ISheet.Cast方法的具体用法?C# ISheet.Cast怎么用?C# ISheet.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISheet
的用法示例。
在下文中一共展示了ISheet.Cast方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteRows
public static void WriteRows(StreamWriter s, ISheet sheet, Language language, IEnumerable<int> colIndices, bool writeRaw)
{
foreach (var row in sheet.Cast<Ex.IRow>().OrderBy(_ => _.Key)) {
var useRow = row;
if (useRow is IXivRow)
useRow = ((IXivRow)row).SourceRow;
var multiRow = useRow as IMultiRow;
s.Write(useRow.Key);
foreach (var col in colIndices) {
object v;
if (language == Language.None || multiRow == null)
v = writeRaw ? useRow.GetRaw(col) : useRow[col];
else
v = writeRaw ? multiRow.GetRaw(col, language) : multiRow[col, language];
if (v == null)
s.Write(",");
else if (v is IDictionary<int, object>)
WriteDict(s, v as IDictionary<int, object>);
else if (IsUnescaped(v))
s.Write(",{0}", v);
else
{
// This prevents new lines from appearing in CSV
// which results in invalid CSV output.
string nv = v.ToString().Replace("\"", "\"\"");
nv = Regex.Replace(nv, @"\t|\n|\r", "");
s.Write(",\"{0}\"", nv);
}
}
s.WriteLine();
s.Flush();
}
}