本文整理汇总了C#中String.IsNotNullOrWhiteSpace方法的典型用法代码示例。如果您正苦于以下问题:C# String.IsNotNullOrWhiteSpace方法的具体用法?C# String.IsNotNullOrWhiteSpace怎么用?C# String.IsNotNullOrWhiteSpace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String.IsNotNullOrWhiteSpace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportExcel
public static DataSet ImportExcel(this DataSet dataSet, String filename, bool hasHeaders = true)
{
if (filename.IsNotNullOrWhiteSpace()) return default(DataSet);
var connectionString = String.Empty;
var HDR = hasHeaders ? "Yes" : "No";
var extension = Path.GetExtension(filename);
if (extension.IsNotNullOrWhiteSpace())
switch (extension.Substring(1))
{
case "xls": //Excel 97-03
connectionString = String.Format(
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1};IMEX=1'",
filename, HDR);
break;
case "xlsx": //Excel 07
connectionString = String.Format(
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1};IMEX=1'",
filename, HDR);
break;
}
dataSet = new DataSet(Path.GetFileNameWithoutExtension(filename));
using (var conOleDb = new OleDbConnection(connectionString))
{
conOleDb.Open();
//{TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE}
var arrRestrict = new Object[] {null, null, null, "TABLE"};
var dtSchema = conOleDb.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, arrRestrict);
if (null != dtSchema)
{
foreach (DataRow drSchema in dtSchema.Rows)
{
var nameSheet =
//drSchema[dtSchema.Columns[2].ColumnName].ToString();
drSchema["TABLE_NAME"].ToString();
var selectQuery = String.Format("SELECT * FROM [{0}]", nameSheet);
var table = new DataTable(nameSheet);
var cmdOleDb = new OleDbCommand(selectQuery, conOleDb) { CommandType = CommandType.Text };
new OleDbDataAdapter(cmdOleDb).Fill(table);
dataSet.Tables.Add(table);
}
}
conOleDb.Close();
}
RemoveNull(dataSet);
return dataSet;
}