我正在进行一些单元测试,我想知道是否有任何方法可以测试列表是否按其包含的对象的属性排序.
现在我这样做,但我不喜欢它,我想要一个更好的方法.有人可以帮帮我吗?
// (fill the list)
List<StudyFeedItem> studyFeeds =
Feeds.GetStudyFeeds(2120, DateTime.Today.AddDays(-200), 20);
StudyFeedItem previous = studyFeeds.First();
foreach (StudyFeedItem item in studyFeeds)
{
if (item != previous)
{
Assert.IsTrue(previous.Date > item.Date);
}
previous = item;
}
Run Code Online (Sandbox Code Playgroud) 我需要使用现有表(例如,3列)打开现有Word文档(.docx)并向该表添加新行.有没有办法做到这一点?我正在使用Open XML
我正在创建这样的表(第一次):
Table tbl = new Table();
// Set the style and width for the table.
TableProperties tableProp = new TableProperties();
TableStyle tableStyle = new TableStyle() { Val = "TableGrid" };
// Make the table width 100% of the page width.
TableWidth tableWidth = new TableWidth() { Width = "5000", Type = TableWidthUnitValues.Pct };
// Apply
tableProp.Append(tableStyle, tableWidth);
tbl.AppendChild(tableProp);
// Add 3 columns to the table.
TableGrid tg = new TableGrid(new GridColumn(), new GridColumn(), new GridColumn());
tbl.AppendChild(tg);
// Create …
Run Code Online (Sandbox Code Playgroud) 我需要打开一个现有的 Excel文件并用DataTable填充它。我怎样才能做到这一点?
我在 ASP.NET 工作
我已经尝试使用此解决方案(http://stackoverflow.com/questions/1746701/export-datatable-to-excel-file)创建一个 excel,然后我尝试使用这样的 OLEDB 连接打开它,但它没有用..它说表格格式不正确..然后它说我找不到ISAM文件..我不知道该怎么办..
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\reports\report.xls;Extended Properties=""Excel 8.0;HDR=No;IMEX=1""");
conn.Open();
System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = @"SELECT * INTO [Excel 8.0;Database=C:\reports\reportBase.xls].[SheetBase1] FROM Sheet1]";
cmd.ExecuteNonQuery();
conn.Close();
Run Code Online (Sandbox Code Playgroud)
请帮我!!我很绝望!!
谢谢!!