-
Notifications
You must be signed in to change notification settings - Fork 891
Inserting and Deleting Columns
Francois Botha edited this page Oct 22, 2016
·
2 revisions
var workbook = new XLWorkbook();
var ws = workbook.Worksheets.Add("Inserting and Deleting Columns");
// Range starts with 2 columns
var rng = ws.Range("B2:C3"); // Range starts on B2
// Insert a column before the range
ws.Column(1).InsertColumnsAfter(1); // Range starts on C2
// Insert a column in between the range
ws.Column(3).InsertColumnsAfter(1); // Range now has 3 columns
// Insert a column (from a range) before the range
ws.Range("A2:A3").InsertColumnsAfter(1); // Range starts on D2
// Insert a column (from a range) in between the range
ws.Range("D2:D3").InsertColumnsAfter(1); // Range now has 4 columns
// Inserting columns from a range not covering all columns does not affect our defined range
ws.Range("A1:A2").InsertColumnsAfter(1);
ws.Range("E3:E4").InsertColumnsAfter(1);
// Delete a column before the range
ws.Column(1).Delete(); // Range starts on C2
// Delete a column (from a range) before the range
ws.Range("A2:A3").Delete(XLShiftDeletedCells.ShiftCellsLeft); // Range starts on B2
// Delete a column in between the range
ws.Column(3).Delete(); // Range now has 3 columns
// Delete a column (from a range) in between the range
ws.Range("C2:C3").Delete(XLShiftDeletedCells.ShiftCellsLeft); // Range now has 2 columns
// Deleting columns from a range not covering all columns does not affect our defined range
ws.Range("A1:A2").Delete(XLShiftDeletedCells.ShiftCellsLeft);
ws.Range("D3:D4").Delete(XLShiftDeletedCells.ShiftCellsLeft);
rng.Style.Fill.BackgroundColor = XLColor.Orange;
workbook.SaveAs("InsertingAndDeletingColumns.xlsx");
- How do I deliver an Excel file in ASP.NET?
- Does it support Excel 2003 and prior formats (.xls)?
- How can I insert an image?
- Text with numbers are getting converted to numbers, what's up with that?
- How do I get the result of a formula?
- Data Types
- Creating Multiple Worksheets
- Organizing Sheets
- Loading and Modifying Files
- Using Lambda Expressions
- Cell Values
- Workbook Properties
- Using Formulas
- Evaluating Formulas
- Creating Rows And Columns Outlines
- Hide Unhide Rows And Columns
- Freeze Panes
- Copying Worksheets
- Using Hyperlinks
- Data Validation
- Hide Worksheets
- Sheet Protection
- Tab Colors
- Conditional Formatting
- Pivot Table example
- Sparklines
- Copying IEnumerable Collections
- Inserting Data
- Inserting Tables
- Adding DataTable as Worksheet
- Adding DataSet
- Styles - Alignment
- Styles - Border
- Styles - Fill
- Styles - Font
- Styles - NumberFormat
- NumberFormatId Lookup Table
- Style Worksheet
- Style Rows and Columns
- Using Default Styles
- Using Colors
- ClosedXML Predefined Colors
- Excel Indexed Colors
- Using Rich Text
- Using Phonetics
- Defining Ranges
- Merging Cells
- Clearing Ranges
- Deleting Ranges
- Multiple Ranges
- Shifting Ranges
- Transpose Ranges
- Named Ranges
- Accessing Named Ranges
- Copying Ranges
- Using Tables
- Sorting Data
- Selecting Cells and Ranges
- Row Height and Styles
- Selecting Rows
- Inserting Rows
- Inserting and Deleting Rows
- Adjust Row Height and Column Width to Contents
- Row Cells
- Column Width and Styles
- Selecting Columns
- Inserting Columns
- Inserting and Deleting Columns
- Adjust Row Height and Column Width to Contents
- Column Cells
- Pages Tab
- Paper Size Lookup Table
- Margins Tab
- Headers and Footers Tab
- Sheet Tab
- Print Areas and Page Breaks