C# 导出excel如何隐藏列或设置列不可编辑
试了这个"worksheet.get_Range("N1","N2").EntireColumn.Hidden=true;"不行...
试了这个"worksheet.get_Range("N1", "N2").EntireColumn.Hidden = true;"不行
展开
展开全部
dt.Columns.Add("类型", typeof(string));
dt.Columns.Add("大类", typeof(string));
dt.Columns.Add("子类", typeof(string));
int sum = Convert.ToInt32(biao3.Rows.Count.ToString());
//string sum = biao3.Rows.Count.ToString();
// textBox1.Text = sum.ToString();
for (int i=0; i < sum;i++ )
try
{ dt.Rows.Add(new object[] { biao3.Rows[i][4].ToString(), biao3.Rows[i][5].ToString(), biao3.Rows[i][6].ToString() }); }
catch
{ dt.Rows.Add(new object[] { "null", "null", "null" }); }
this.dataGridView1.AutoGenerateColumns = false; // 不允许自动创建列
// 添加字段。
DataGridViewTextBoxColumn col1 = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn col2 = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn col3 = new DataGridViewTextBoxColumn();
col1.HeaderText = "类型";
col2.HeaderText = "大类";
col3.HeaderText = "子类";
col1.DataPropertyName = "类型";
col2.DataPropertyName = "大类";
col3.DataPropertyName = "子类";
this.dataGridView1.Columns.Add(col1);
this.dataGridView1.Columns.Add(col2);
this.dataGridView1.Columns.Add(col3);
this.dataGridView1.DataSource =dt;
dt.Columns.Add("大类", typeof(string));
dt.Columns.Add("子类", typeof(string));
int sum = Convert.ToInt32(biao3.Rows.Count.ToString());
//string sum = biao3.Rows.Count.ToString();
// textBox1.Text = sum.ToString();
for (int i=0; i < sum;i++ )
try
{ dt.Rows.Add(new object[] { biao3.Rows[i][4].ToString(), biao3.Rows[i][5].ToString(), biao3.Rows[i][6].ToString() }); }
catch
{ dt.Rows.Add(new object[] { "null", "null", "null" }); }
this.dataGridView1.AutoGenerateColumns = false; // 不允许自动创建列
// 添加字段。
DataGridViewTextBoxColumn col1 = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn col2 = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn col3 = new DataGridViewTextBoxColumn();
col1.HeaderText = "类型";
col2.HeaderText = "大类";
col3.HeaderText = "子类";
col1.DataPropertyName = "类型";
col2.DataPropertyName = "大类";
col3.DataPropertyName = "子类";
this.dataGridView1.Columns.Add(col1);
this.dataGridView1.Columns.Add(col2);
this.dataGridView1.Columns.Add(col3);
this.dataGridView1.DataSource =dt;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询