Cut and paste an entire Excel column

I am looking for an example cut code and paste the entire column in Excel.

+3
source share
5 answers

Assuming you know how to cut and paste a range, simply specify the range using the letter of the column. eg. Range("A:A")indicates the entire column A.

+1
source

Here the pattern cuts and pastes the row. Converting it to a column should be trivial

+1
source

: Excel? , CSV - . .

- ( Excel):

xlobj.workbook("workbook1.xls").sheets("Sheet1").Columns("C:C").Cut
xlobj.workbook("workbook1.xls").sheets("Sheet1").Columns("A:A").Paste
0
source

Using the Microsoft Excel 12.0 Object Library (Microsoft.Office.Interop.Excel)

Application app = new Application();
Workbook wb = app.Workbooks.Open("test.xlsx");
Worksheet ws = wb.Sheets["MyTestSheet"];
Range rngSource = ws.UsedRange.Columns["A"];
Range rngTarget = ws.UsedRange.Columns["D"];
rngTarget.Value = rngSource.Value;
rngSource.Value = null;
wb.Save();
app.Application.Quit();

You can do the same with fewer lines of code, but for demo purposes, I wrote it like this. Keep in mind that the above code violates "Never use 2 points when accessing COM objects", which can cause problems with deleting COM objects and leave zombie Excel processes.

0
source

Use the "EntireColumn" property, for which it is intended for:

string rangeQuery = "A1:A1";

Range range = workSheet.get_Range(rangeQuery, Type.Missing);

range = range.EntireColumn;
0
source

All Articles