我有datagridview
一些记录。我必须以 .txt 文件格式导出此记录。当它导出为 .txt 文件时,记录的格式不正确,如附图所示
我已经编写了一些用于导出到 .txt 文件的代码
string FileName = CurrentUserContext.CurrentEnterprise.FSaveReportTo+"\\" + fExpFile.strFileName + ".txt";
bool IncludeColHeaders = fExpFile.includeHeaders;
StringBuilder sb = new StringBuilder();
if (Company != null)
{
sb.AppendLine("Company: " + Company.FName);
}
sb.AppendLine("Bank: " + Bank.FBankName + "\t" + Bank.FBankNo);
sb.AppendLine("Account: " + Bank.FAccountName + "\t" + Bank.FAccountNo);
sb.AppendLine("\n");
string strColumnHeaders = null;
int ColumnCount = this.dgvCheckdetails.ColumnCount;
if (IncludeColHeaders)
{
for (int j = 0; j <= ColumnCount - 2; j++)
{
if (j == 3 || j == 5)
{
strColumnHeaders += "\t\t";
}
if (j != 4)
{
strColumnHeaders += dgvCheckdetails.Columns[j].HeaderText + "\t";
}
}
sb.AppendLine(strColumnHeaders);
}
int rowcount = dgvCheckdetails.Rows.Count;
string strRow;
for (int i = 0; i <= rowcount - 1; i++)
{
strRow = null;
for (int j = 0; j <= ColumnCount - 2; j++)
{
if (j != 4)
strRow += Convert.ToString(dgvCheckdetails.Rows[i].Cells[j].Value) + "\t";
}
sb.AppendLine(strRow);
}
File.WriteAllText(FileName, sb.ToString());
MessageBox.Show(CultureManager.GetMessageString("Export_Data_Successfully_Exported"));
如何对齐从导出的 .txt 文件中的列datagridview
?