日期:2014-05-17  浏览次数:20836 次

使用'/n'和substring的问题

做的打印程序,每7个字换一行打印
Cell[1]的内容为:“ZA卓能菁采新生眼部淡纹精华霜”
现在打印预览中少了“华霜”这两个字,求教原因和解决方法
代码如下:
C# code

 for (int j = row; j < data_list.Rows.Count - 1; j++)
            {
                #region 每条记录的打印数量
                //DGV中每条记录的打印数量
                for (int p = col; p < int.Parse(data_list.Rows[j].Cells[6].Value.ToString()); p++)
                {
                    col++;
                    #region 判断DataGridView是否为空
                    foreach (object cell in data_list.Rows[j].Cells)
                    {
                        //判断DataGridView是否为空
                        DataGridViewCell d = (DataGridViewCell)cell;
                        if (d.Value == null)
                        {
                            MessageBox.Show("数据输入不完整", "错误提示");
                            return;
                        }

                        //取得DATAGRIDVIEW单行的内容

                        #region
//自动折行计算
if (data_list.Rows[j].Cells[1].Value.ToString().Length > 7)
data_list.Rows[j].Cells[1].Value = data_list.Rows[j].Cells[1].Value.ToString().Substring(0, 6).Trim()+
'\n' + data_list.Rows[j].Cells[1].Value.ToString().Substring(6, 8).Trim() +
'\n' + data_list.Rows[j].Cells[1].Value.ToString().Substring(14, data_list.Rows[j].Cells[1].Value.ToString().Length - 14)).ToString()).Trim();
}



------解决方案--------------------
substring(a,b)是指从第a个字符开始取b个字符。
楼主的自动折行计算有问题