简体   繁体   English

在C#中读取Excel文件时查找标签列宽

[英]To find label column width while Reading Excel File in C#

I am reading an excel file from a WPF application. 我正在从WPF应用程序读取Excel文件。 For some purpose I need the column width as per in the label ("A", "B", "C" ... in the excel sheet). 出于某种目的,我需要按照标签中的列宽(Excel工作表中的“ A”,“ B”,“ C” ...)进行操作。 The width variable in the Range always provides the particular cells width. “范围”中的width变量始终提供特定的像元宽度。 If the cell belongs to a merged cell (previous column or previous row), reading the perticular cell width, results in a null. 如果该单元格属于合并的单元格(上一列或上一行),则读取垂直单元格的宽度将导致结果为空。 So, I need the width of the column labels or the height of row labels ("1", "2", ...) not the cell height ! 因此,我需要列标签的宽度或行标签的高度(“ 1”,“ 2”,...)而不是单元格的高度!

KB KB

Find your Range ( Application.Selection or Application.ActiveCell or Range[..,..] , ...) 查找您的RangeApplication.SelectionApplication.ActiveCellRange[..,..] ,...)

and use Range.ColumnWidth . 并使用Range.ColumnWidth for column width: 对于列宽:

var width = worksheet.Range["A1", "A5"].ColumnWidth;

and use Range.Value or Range.Parse for values of range. 并使用Range.ValueRange.Parse作为range的值。

var value = worksheet.Range["A1", "A5"].Value;

Working with Range have more benefits! 使用Range有更多好处!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM