0
A
回答
1
不要知道C#是不是我的强项和下方可能无法做到这一点的理想方式。如果你找到更合适的,我非常想听听吧:)
我已经找到了包括基于CSV元数据到我BIML项目最简单的方法是将其加载到C#DataTable
然后我在Biml中引用的对象是一个C#变量对象,它与foreach
一起很好地遍历行。
假设你知道如何在您的BIML项目C#(直接或通过引用.cs
文件的文件中),你可以使用下面的代码:
public static DataTable FlatFileToDataTable(string filePath, char delimiter)
{
DataTable dt = new DataTable();
using (StreamReader sr = new StreamReader(filePath))
{
string[] headers = sr.ReadLine().Split(delimiter);
foreach (string header in headers)
{
dt.Columns.Add(header);
}
while (!sr.EndOfStream)
{
string[] rows = sr.ReadLine().Split(delimiter);
DataRow dr = dt.NewRow();
for (int i = 0; i < headers.Length; i++)
{
dr[i] = rows[i];
}
dt.Rows.Add(dr);
}
}
return dt;
}
我认为,以使用StreamReader
您还需要将using System.IO;
添加到您的代码文件中。
用法是定义一个DataTable
对象,并使用上述的结果填充它,然后使用内BIML代码段引用它:
DataTable YourDataTable = FlatFileToDataTable("<Path to CSV file>",'<Value Delimiter>');
...
<Columns>
<# foreach(DataRow r in YourDataTable.Rows){ #>
<Column Name="<#=r["YourColumnName"]#>" etc />
<# } #>
</Columns>
相关问题
- 1. red5 web应用程序提供外部静态资源
- 2. Laravel使资源只提供给来宾用户
- 3. 想给ASP.NET提供专业外观吗?
- 4. gocd - 使提供给代理
- 5. 提供给PHP
- 6. 从外部库提供静态文件
- 7. 外部角色提供者和编译?
- 8. Spring,JndiTemplate外部化提供程序URL
- 9. 通过Sharepoint 2010提供的外部HTML
- 10. 从外部root/index.php提供php方法
- 11. 隐藏外部提供的iframe
- 12. Django模型外部提供的字段
- 13. 如何向UIButton提供外部属性
- 14. Azure VM不提供外部网站
- 15. 如何在php中使用echo提供外部链接?
- 16. 使用来自外部数据提供者(API)的数据
- 17. 如何使用Tapestry5从外部上下文提供文件5
- 18. 使用API将网络添加到外部提供商
- 19. 如何使用PHP从Web根外部提供文档?
- 20. 使用外部课程提供的信息:囚徒困境
- 21. 为quantstrat使用外部提供的指标数据
- 22. 使用StoredProcedure类型的SqlCommand是否提供外部事务?
- 23. 使用ProcessBuilder执行外部程序并提供输入
- 24. 如何在Rails REST API中使用外部提供的ID?
- 25. 使用外部令牌提供程序的蓝色APIConnect OAuth 2.0
- 26. 使用提供者的SSIS OLE DB源
- 27. 使用poi-ooxml打破资源提供
- 28. 分配属性使用BIML
- 29. Spring:在Web应用程序的上下文根外部提供静态资源
- 30. 使用RewriteRule给index.php提供参数
是。显示一些示例数据以及如何使用它来制作包和任务 – billinkc