小编Nic*_*ole的帖子

如何检查列表是否已订购?

我正在进行一些单元测试,我想知道是否有任何方法可以测试列表是否按其包含的对象的属性排序.

现在我这样做,但我不喜欢它,我想要一个更好的方法.有人可以帮帮我吗?

// (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)

c# unit-testing list html-lists

55
推荐指数
10
解决办法
4万
查看次数

向Word文档中的现有表添加一行(打开XML)

我需要使用现有表(例如,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)

c# ms-word openxml

14
推荐指数
2
解决办法
3万
查看次数

将数据表导出到现有 Excel

我需要打开一个现有的 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)

请帮我!!我很绝望!!

谢谢!!

c# excel oledbconnection

0
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×3

excel ×1

html-lists ×1

list ×1

ms-word ×1

oledbconnection ×1

openxml ×1

unit-testing ×1