格式化LINQtoCSV输出 [英] formatting LINQtoCSV output
问题描述
您好我使用以下代码导出queryResult中的数据:
Hi I'm using the below code to export the data in queryResult:
private void btnDownload_Click(object sender, EventArgs e)
{
var queryResult = from s in context.Contacts
join c in context.Address on s.ContactID equals c.Contact.ContactID
select new
{
s.FirstName,
s.LastName,
s.ContactNumber,
//s.Addresses,
c.Address1,
c.Mortgage,
c.RemainingMortgage,
c.Rent,
c.Period,
c.RentArrears,
c.Rates,
c.RateArrears,
c.RatesUpToDate,
c.Repairs
};
CsvFileDescription outputFileDescription = new CsvFileDescription
{
SeparatorChar = '\t', // tab delimited
FirstLineHasColumnNames = true,
FileCultureName = "en-GB" // use formats used in UK
};
CsvContext cc = new CsvContext();
// Write contents of productsNetherlands to file
cc.Write(
queryResult,
"Houses.csv",
outputFileDescription);
}
我对创建的CSV文件有几个问题:
1 )我的标题col在输出的CSV中有列名,它们在单元格A1中一起列为1个字符串
2)表单上的地址字段是丰富的文本框所以当输入一个带有返回键的地址时,这会将输出的字符串拆分为CSV文件(停止这种情况的一种方法是为地址的每个部分设置单独的文本框,但是我的问题是否有解决办法?)
3)一旦所有数据写成功,我可以将文件写入文件目录吗?
I've a couple of questions regarding the created CSV file:
1)my header col has the column names yet in the outputted CSV they are listed together in Cell A1 as 1 string
2)The address field on the form is a rich text box so when an address with return key presses is entered this splits the outputted string in the CSV file (one way to stop this is to have separate text boxes for each part of the address but is there a workaround for my question?)
3) Instead of writing the file to a file directory can I display it to the user once all data has been written successfully?
推荐答案
这篇关于格式化LINQtoCSV输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!