3

I have an Excel File in which I have number of columns. Now I need to insert columns for example between "C" and "D".. so that the resulting columns should be "C" ,"New Column(D)", "E".. Please help me with this..

Parts of Code to open the Excel file is as below...

Microsoft.Office.Interop.Excel.Application application = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook workbook = application.Workbooks.Open(txtDestination.Text.ToString() + "\\" + Path.GetFileName(File_Name, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                    Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                    Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                    Type.Missing, Type.Missing);
Worksheet worksheet = (Worksheet)workbook.ActiveSheet;
4

3 に答える 3

10

私はこのようにします:

隣に新しい列を挿入する列を選択します

Excel.Range oRng = oSheet.Range["I1"];

既存の列をシフトする方向を指定して、新しい列を挿入します。この場合、I1 の左側に新しい列を挿入します。I1はH1になります

oRng.EntireColumn.Insert(Excel.XlInsertShiftDirection.xlShiftToRight, 
                    Excel.XlInsertFormatOrigin.xlFormatFromRightOrBelow);

ヘッダー値の設定など、新しい列で何かを行うには、I1 範囲を再度選択します。

oRng = oSheet.Range["I1"];

列ヘッダーのテキストを設定する

oRng.Value2 = "Discount";
于 2014-04-07T23:59:31.337 に答える
0
Microsoft.Office.Interop.Excel.Application application = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook workbook = application.Workbooks.Open(txtDestination.Text.ToString() + "\\" + Path.GetFileName(File_Name, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                    Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                    Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                    Type.Missing, Type.Missing);
Worksheet worksheet = (Worksheet)workbook.ActiveSheet;
于 2014-03-05T04:31:32.657 に答える
0

上記のコメントを回答として再投稿すると、質問が回答済みとしてマークされる場合があります。

参照してください: Excelソリューションの Excel テーブルの先頭に新しい列を追加する. 「A1」の値を前に挿入したい列に変更するだけです(例では「D1」)

于 2013-09-04T06:08:47.397 に答える