我正在導出datagridview的數據轉換成文本文件的格式, 創建我嘗試下面的代碼請保存位置的文本文件中使用C#
string dirLocationString = @"C:\Users\palanar\Desktop\result.txt";
StreamWriter sW = new StreamWriter(dirLocationString);
string lines = "";
lines = "DateTime" + "\t" + "TestStatus" + "\t" + "BatPackSN" + "\t" + "CellSN"
+ "\t" + "BlockSN" + "\t" + "UI_ID" + "\t" + "UI_ParentID" + "\t" + "OperationNumber"
+ "\t" + "OperationName" + "\t" + "EquipmentNumber" + "\t" + "EquipmentName" + "\t" + "WorkOrder"
+ "\t" + "Assembly" + "\t" + "ProductName" + "\t" + "HandlingDuration" + "\t" + "OperationDuration"
+ "\t" + "RepairID" + "\t" + "DefectID" + "\t" + "UitemLevelCode" + "\t" + "UIEventLevelCode";
sW.WriteLine(lines);
for (int row = 0; row < dataGridView2.Rows.Count - 1; row++)
{
string lines1 = "";
for (int col = 0; col <= 19; col++)
{
lines1 += (string.IsNullOrEmpty(lines1) ? " " : "\t") + dataGridView2.Rows[row].Cells[col].Value.ToString();
}
sW.WriteLine(lines1);
}
這裏的數據是完全導出並保存爲文本文件的格式,問題是在這裏我已經指定了默認位置,而不是它應該通過打開保存對話來請求位置。
窗口或網頁??? – 2015-02-06 06:38:31
@Ganesh_Devlekar,Windows桌面應用程序。 – 2015-02-06 06:39:22
注意:使用'IDisposable'工作時,將它包裝成''using',在你的情況下'使用(StreamWriter sW = new StreamWriter ...){...}' – 2015-02-06 06:42:04