OpenXML Selecting a Specific Column

I'm trying to select a specific column to automatically set its width, but I have little success. Should I not use the MSDN version of GetRow to select a column from the column collection?

return worksheet.GetFirstChild<SheetData>().Elements<Row>().Where(r => r.RowIndex == rowIndex).First();

return worksheet.GetFirstChild<SheetData>().Elements<Column>().Where(r => r.Min== columnNumber && r.Max == columnNumber).First();

Am I right? FWIW I know how to create a column from scratch and set the width, but this is not possible because I do not know what data will be inside the columns when I create them in my constructor.

+3
source share
3 answers

You can add a column object to the worksheet. Then I created a method that sets the width.

Worksheet ws = new Worksheet();
Columns columns = new Columns();

columns.Append(CreateColumnData(1, 1, 14.87));

ws.append(columns);


private static Column CreateColumnData(UInt32 StartColumnIndex, UInt32 EndColumnIndex, double ColumnWidth)
    {
        Column column;
        column = new Column();
        column.Min = StartColumnIndex;
        column.Max = EndColumnIndex;
        column.Width = ColumnWidth;
        column.CustomWidth = true;
        return column;
    }
+1
source

, , . , , , , . , .net openxml-, DocumentFormat.OpenXml , Office.Interop. azure, Office.Interop. closedxml, openxml, Office.Interop. .

0

All Articles