如何使用DocumentFormat.OpenXml C#获取excel工作表中的特定列? [英] How can I get the specific column in excel worksheet using DocumentFormat.OpenXml C#?

查看:71
本文介绍了如何使用DocumentFormat.OpenXml C#获取excel工作表中的特定列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为标题,我想使用C#中的OpenXML在excel工作表中获取特定列以设置隐藏属性.像这样:

As the title, I would like to get a specific column in excel worksheet using OpenXML in C# for setting hidden property. Like that:

var columns = worksheet.GetFirstChild<Columns>();
var column = columns.FirstOrDefault(c=>c.ColumnIndex == 4);
column.Hidden = true;

上面的代码只是我的想法的一个示例.有什么办法可以解决我的问题?

The code above is just a sample for my idea. Is there any way for solving my problem?

推荐答案

每: workSheetPart.Worksheet.Descendants()给出了columnGroup,而不是通常意义上的列.这里的列"用词不当,其后果是像弹出这样的问题.

workSheetPart.Worksheet.Descendants() in fact gives the columnGroup, not columns in the common sense; here the "column" is a misnomer and it has consequences like questions like this pop out.

一旦获得了列组,就可以使用其最小"和最大"属性来获取其中的列.

Once you get the column group, you can use its "Min" and "Max" attribute to get the columns in it.

这篇关于如何使用DocumentFormat.OpenXml C#获取excel工作表中的特定列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆