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


C# Range.Select方法代码示例

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


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

示例1: AddRow

 /// <summary>
 /// Метод добавляет пустую строку.
 /// </summary>
 /// <param name="rowNum">Номер строки</param>
 public void AddRow(int rowNum)
 {
     _range = (Excel.Range)_xlWorkSheet.Rows[rowNum, _misValue];
     _range.Select();
     _range.Insert(Excel.XlInsertShiftDirection.xlShiftDown, _misValue);
 }
开发者ID:IgorGorbunov,项目名称:SmartLabParser,代码行数:10,代码来源:ExcelClass.cs

示例2: CreateExcelItem


//.........这里部分代码省略.........
            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];
            }

            // заполняем ячейки
            for (int i = 0; i < 16; i++)
            {
                // выделяем нужный лист
                excelworksheet = (Excel.Worksheet)excelsheets.get_Item(i + 1);
                excelworksheet.Activate();

                excelcells = excelworksheet.get_Range("A3", "A514");
                excelcells.Value2 = i;

                progressBar3.Value = i;
                // поехали по строкам
                for (int j = 0; j < 512; j++)
                {
                    progressBar2.Value = j;
                    if (Items[i,j].ItemName[0] != '\0')
                    {
                        excelcells = (Excel.Range)excelworksheet.Cells[j + 3, 3];
                        excelcells.Value2 = Items[i, j].ItemName;
                        excelcells.Select();
                    }
                    fixed (Int64* buff = Items[i, j].Numbers)
                    {
                        for (int k = 0; k < MyItemColumns.Length; k++)
                        {
                            if (buff != null && *(buff + k) != 0.0f)
                            {
                                excelcells = (Excel.Range)excelworksheet.Cells[j + 3, k + 4];
                                excelcells.Value2 = *(buff + k);
                            }
                        }
                    }
                }
            }

            // показываем готовый файл
            excelapp.Visible = true;
            progressBar2.Value = 0;
            progressBar3.Value = 0;
            MessageBox.Show("All Done!");
        }
开发者ID:samik3k,项目名称:BMDtoExcel,代码行数:101,代码来源:Form1.cs

示例3: btnExcel_Click

        private void btnExcel_Click(object sender, EventArgs e)
        {
            if ( !timer1.Enabled )
                btnStart_Click(sender, e);
               object misValue = System.Reflection.Missing.Value;
                xlApp = new Excel.Application();
                xlApp.Visible = false;
                xlWorkBook = xlApp.Workbooks.Add(misValue);
                xlFunction = xlApp.WorksheetFunction;

                xlWorkSheetData = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
                xlWorkSheetData.Name = "Pendulum";
                xlWorkSheetData.Activate();

                xlWorkSheetData.Cells[1, 1] = "Constants used, mass: " + tbm.Text + ", gravity: " + tbG.Text + ", Spring Constant: " + tbk.Text + ", Length: " + tbH.Text;
                xlRng = xlWorkSheetData.get_Range("A1", "N1");
                xlRng.Select();
                xlRng.Merge();

                xlWorkSheetData.Cells[2, 1] = "Initial Values used, Intial X: " + tbXi.Text + ", Initial Y: " + tbYi.Text + ", Initial X Velocity: " + vx0.Text + ", Initial Y Velocity: " + vy0.Text;
                xlRng = xlWorkSheetData.get_Range("A2", "N2");
                xlRng.Select();
                xlRng.Merge();

                xlWorkSheetData.Cells[lastRowExcel, 1] = "t"; // changes these to whatever you want
                xlWorkSheetData.Cells[lastRowExcel, 2] = "X";
                xlWorkSheetData.Cells[lastRowExcel, 3] = "Y";
                xlWorkSheetData.Cells[lastRowExcel, 4] = "Vx";
                xlWorkSheetData.Cells[lastRowExcel, 5] = "Vy";
                lblTransfer.Visible = true;
                for (int i = 0; i < excelData.Count; i++)
                {
                    xlWorkSheetData.Cells[i + 4, 1] = (excelData[i].time / 1000.00).ToString();
                    xlWorkSheetData.Cells[i + 4, 2] = excelData[i].x.ToString();
                    xlWorkSheetData.Cells[i + 4, 3] = excelData[i].y.ToString();
                    xlWorkSheetData.Cells[i + 4, 4] = excelData[i].vx.ToString();
                    xlWorkSheetData.Cells[i + 4, 5] = excelData[i].vy.ToString();
                }
                lblTransfer.Visible = false;
                try //essaye le sauvegarde
                {

                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        //sauvegarde le classeur courant
                        xlWorkBook.SaveAs(saveFileDialog1.FileName,
                            Excel.XlFileFormat.xlWorkbookDefault, misValue,
                            misValue, misValue, misValue,
                            Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue,
                            misValue, misValue, misValue);
                        xlWorkBook.Close();
                    }

                }
                catch //en cas d'erreur affiche le message
                {
                    MessageBox.Show("Impossible de sauvegarder le fichier.", "Erreur de sauvegarde de fichier Excel", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
        }
开发者ID:harley1011,项目名称:Physics_Simulations-Winforms,代码行数:59,代码来源:Form1.cs


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