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