c# 操作Excel 如何设置换行
stringproductName="";foreach(OrderItemInfoorderIteminorderItemList){productName+=orde...
string productName = "";
foreach(OrderItemInfo orderItem in orderItemList)
{
productName += orderItem.ProductName + ",";//列出商品名称
}
objSheet.Cells[temp + 2, 2] = productName;
如何在变量productName追加之前换行?试过用\n可以换行,但是效果不对,猜想高度和宽度似乎按文本的比例变化。求解? 展开
foreach(OrderItemInfo orderItem in orderItemList)
{
productName += orderItem.ProductName + ",";//列出商品名称
}
objSheet.Cells[temp + 2, 2] = productName;
如何在变量productName追加之前换行?试过用\n可以换行,但是效果不对,猜想高度和宽度似乎按文本的比例变化。求解? 展开
展开全部
SaveFileDialog kk = new SaveFileDialog();
kk.Title = "保存EXECL文件";
kk.Filter = "excel(*.xls) |*.xls |所有文件(*.*) |*.*";
kk.FilterIndex = 1;
if (kk.ShowDialog() == DialogResult.OK)
{
string FileName = kk.FileName;
if (File.Exists(FileName))
File.Delete(FileName);
FileStream objFileStream;
StreamWriter objStreamWriter;
objFileStream = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write);
objStreamWriter = new StreamWriter(objFileStream, System.Text.Encoding.Unicode);
objStreamWriter.WriteLine("<table><tr><td>" + "aa" + "<br style='mso-data-placement:same-cell;'/> " + "cc" + "<br style='mso-data-placement:same-cell;'/> " + "dd" + "</td><td>"+"pp"+"</td></tr></table>");
//objStreamWriter.WriteLine("aaaa" + Convert.ToChar(10) + "bbb");
objStreamWriter.Close();
objFileStream.Close();
MessageBox.Show(this, "保存EXCEL成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
kk.Title = "保存EXECL文件";
kk.Filter = "excel(*.xls) |*.xls |所有文件(*.*) |*.*";
kk.FilterIndex = 1;
if (kk.ShowDialog() == DialogResult.OK)
{
string FileName = kk.FileName;
if (File.Exists(FileName))
File.Delete(FileName);
FileStream objFileStream;
StreamWriter objStreamWriter;
objFileStream = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write);
objStreamWriter = new StreamWriter(objFileStream, System.Text.Encoding.Unicode);
objStreamWriter.WriteLine("<table><tr><td>" + "aa" + "<br style='mso-data-placement:same-cell;'/> " + "cc" + "<br style='mso-data-placement:same-cell;'/> " + "dd" + "</td><td>"+"pp"+"</td></tr></table>");
//objStreamWriter.WriteLine("aaaa" + Convert.ToChar(10) + "bbb");
objStreamWriter.Close();
objFileStream.Close();
MessageBox.Show(this, "保存EXCEL成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-19
展开全部
\\n 第一个\为转义字符
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
objSheet.Cells[temp + 2, 2] = Convert.ToChar(10) + productName;
Convert.ToChar(10) Excel单元格内换行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询