当前位置: 首页>>代码示例>>C#>>正文


C# Range.AutoFill方法代码示例

本文整理汇总了C#中Microsoft.Office.Interop.Excel.Range.AutoFill方法的典型用法代码示例。如果您正苦于以下问题:C# Range.AutoFill方法的具体用法?C# Range.AutoFill怎么用?C# Range.AutoFill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Office.Interop.Excel.Range的用法示例。


在下文中一共展示了Range.AutoFill方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateExcelItem

        private unsafe void CreateExcelItem()
        {
            // Создаем документ с 16 страницами
            excelapp = new Excel.Application();
            //excelapp.Visible=true;

            excelapp.SheetsInNewWorkbook=1;
            Excel.Workbook excelappworkbook = excelapp.Workbooks.Add(Type.Missing);

            String[] SheetsName = new String[16] { "Sword", "Axe", "MaceScepter", "Spear", "BowCrossbow", "Staff", "Shield", "Helm", "Armor", "Pants", "Gloves", "Boots", "Accessories", "Misc1", "Misc2", "Scrolls" };

            excelsheets = excelappworkbook.Worksheets;

            // определяем имена страницам и переходим на страницу
            excelworksheet = (Excel.Worksheet)excelsheets.get_Item(0 + 1);
            excelworksheet.Name = SheetsName[0];
            excelworksheet.Activate();
            excelworksheet.Application.ActiveWindow.SplitColumn = 3;
            excelworksheet.Application.ActiveWindow.SplitRow = 2;
            excelworksheet.Application.ActiveWindow.FreezePanes = true;

            // заполнение Index (0.1.2.3...)
            excelcells = excelworksheet.get_Range("B3", Type.Missing);
            excelcells.Value2 = 0;
            excelcells = excelworksheet.get_Range("B4", Type.Missing);
            excelcells.Value2 = 1;
            excelcells = excelworksheet.get_Range("B3", "B4");
            Excel.Range dest = excelworksheet.get_Range("B3", "B514");
            excelcells.AutoFill(dest, Excel.XlAutoFillType.xlFillDefault);

            // сворачиваем для увеличения скорости
            excelworksheet.Application.WindowState = Excel.XlWindowState.xlMinimized;
            excelworksheet.Application.Visible = false;

            // оцентровываем первую строку
            excelcells = (Excel.Range)excelworksheet.Rows["1", Type.Missing];
            excelcells.HorizontalAlignment = Excel.Constants.xlCenter;

            // зажирняем и оцентровываем вторую строку
            excelcells = (Excel.Range)excelworksheet.Rows["2", Type.Missing];
            excelcells.Font.Bold = true;
            excelcells.HorizontalAlignment = Excel.Constants.xlCenter;

            // устанавливаем размер колонок
            excelcells = (Excel.Range)excelworksheet.Columns["A", Type.Missing];
            excelcells.ColumnWidth = 5;
            excelcells = (Excel.Range)excelworksheet.Columns["B", Type.Missing];
            excelcells.ColumnWidth = 5;
            excelcells = (Excel.Range)excelworksheet.Columns["C", Type.Missing];
            excelcells.ColumnWidth = 30;
            for (int j = 0; j < MyItemColumns.Length; j++)
            {
                excelcells = (Excel.Range)excelworksheet.Columns[ColumnTempName[j + 3], Type.Missing];
                excelcells.ColumnWidth = MyItemColumns[j].Width;
            }

            // заполняем первую строку границами как называется не помню
            excelcells = excelworksheet.get_Range("C1", Type.Missing);
            excelcells.Value2 = "Char[30]";
            excelcells.Activate();
            for (int j = 0; j < MyItemColumns.Length; j++)
            {
                excelcells = excelapp.ActiveCell.get_Offset(0, 1);
                excelcells.Value2 = MyItemColumns[j].ColSize;
                excelcells.Activate();
            }

            // заполняем вторую строку названиями
            excelcells = excelworksheet.get_Range("A2", Type.Missing);
            excelcells.Value2 = "Type";
            excelcells = excelworksheet.get_Range("B2", Type.Missing);
            excelcells.Value2 = "Index";
            excelcells = excelworksheet.get_Range("C2", Type.Missing);
            excelcells.Value2 = "Item Name";
            excelcells.Activate();
            for (int j = 0; j < MyItemColumns.Length; j++)
            {
                excelcells = excelapp.ActiveCell.get_Offset(0, 1);
                excelcells.Value2 = MyItemColumns[j].Name;
                excelcells.Activate();
            }

            // обнуляем все ячейки кроме названия
            excelcells = excelworksheet.get_Range("D3", "AR514");
            excelcells.Value2 = 0;

            // number format 12 232 232 для zen
            excelcells = excelworksheet.get_Range("AB3", "AB514");
            excelcells.NumberFormat = "# ##0";

            // копируем листы
            for (int i = 0; i < 15; i++)
            {
                excelworksheet = (Excel.Worksheet)excelsheets.get_Item(i + 1);
                excelworksheet.Copy(Type.Missing, excelworksheet);
                excelworksheet = (Excel.Worksheet)excelsheets.get_Item(i + 2);
                excelworksheet.Name = SheetsName[i + 1];
            }

            // заполняем ячейки
//.........这里部分代码省略.........
开发者ID:samik3k,项目名称:BMDtoExcel,代码行数:101,代码来源:Form1.cs


注:本文中的Microsoft.Office.Interop.Excel.Range.AutoFill方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。