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


C# Worksheet.Activate方法代码示例

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


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

示例1: wrtBySht

        //private void wrtBySht(List<string> workList)
        private void wrtBySht(string shtName)
        {

            xlWorkSht = xlWorkBookTar.Worksheets.get_Item(shtName);
            xlWorkSht.Activate();

            string idx = Util.TaskInfo.TaskSetting.insertPtInstData; // start point index
            Excel.Range rng = xlWorkSht.get_Range(idx, idx);

            DataTable dt;
            if (shtName == "InstrumentClassData")
                dt = Util.DbConn.SqlTsk.GetTable("procGetInstData");
            else
                dt = Util.DbConn.SqlTsk.GetTable("procGetSymData " + shtName);


            int j = 1;
            int i = 0;
            foreach (DataRow row in dt.Rows)
            {
                for (i = 0; i < dt.Columns.Count; i++)
                {
                    rng[j + 1, i + 1].Value = row[i].ToString();

                }
                j++;
                if (j > dt.Rows.Count)
                {
                    break;
                }
            }
            rng[j + 1, 1].Value = "end";

        }
开发者ID:Sho20,项目名称:In2S3D_v4,代码行数:35,代码来源:Write2Exl.cs

示例2: btnExport_Click

        private void btnExport_Click(object sender, RoutedEventArgs e)
        {
            exportProgress.Minimum = 0;
            exportProgress.Maximum = TestInfoList.Count ;
            exportProgress.Value = 0;
            double value = 0;
            UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(exportProgress.SetValue);
            try
            {
                excelApp = new ApplicationClass();
                Workbooks myWorkBooks = excelApp.Workbooks;
                myWorkBooks.Open(templatePath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                Sheets sheets = excelApp.Sheets;
                mySheet1 = (Worksheet)sheets[1];
                mySheet1.Activate();

                int rowCount = TestInfoList.Count + 2; ;//总行数

                //写入参数信息
                int paramCount = 0;//参数行数
                if (IsExportParams)
                {
                    paramCount = ParamList.Count * 4;
                    for (int i = 0; i < ParamList.Count; i++)
                    {
                        Model.Parameter p = ParamList[i];

                        Range r = mySheet1.get_Range(mySheet1.Cells[1, testInfoColumnCount + i * 4 + 1], mySheet1.Cells[1, testInfoColumnCount + i * 4 + 4]);
                        r.Merge();
                        r.Value = p.ParamName;
                        r.Font.Bold = true;
                        r.HorizontalAlignment = XlHAlign.xlHAlignCenter;
                        r.VerticalAlignment = XlHAlign.xlHAlignCenter;

                        Range r1 = mySheet1.get_Range(mySheet1.Cells[2, testInfoColumnCount + i * 4 + 1], mySheet1.Cells[2, testInfoColumnCount + i * 4 + 4]);
                        r1.Value2 = paramContents;
                        r1.Font.Bold = true;

                        r1.EntireColumn.AutoFit();
                    }
                }

                //写入测试信息
                string[,] content = new string[rowCount, testInfoColumnCount + paramCount];
                //double?[,] paramContent = new double?[rowCount, paramCount];

                XDocument xdoc;
                BLL.TB_Dict dictBLL = new BLL.TB_Dict();
                for (int i = 0; i < TestInfoList.Count; i++)
                {
                    int rowIndex = i;
                    Model.TestInfoModel model = TestInfoList[i];

                    content[rowIndex, 0] = string.Format("测试{0}", i + 1);//测试顺序
                    content[rowIndex, 1] = model.Ath_Name;//姓名
                    content[rowIndex, 2] = model.TestDate.ToString("yyyy-MM-dd HH:mm");//测试日期
                    content[rowIndex, 3] = model.DJoint;//测试关节
                    content[rowIndex, 4] = model.DJointSide;//测试侧
                    content[rowIndex, 5] = model.DPlane;//运动方式
                    content[rowIndex, 6] = model.DTestMode;//测试模式
                    content[rowIndex, 7] = model.MotionRange;//运动范围
                    content[rowIndex, 8] = model.Speed;//测试速度
                    content[rowIndex, 9] = model.Break;//休息时间
                    content[rowIndex, 10] = model.NOOfSets;//测试组数
                    content[rowIndex, 11] = model.NOOfRepetitions;//重复次数
                    content[rowIndex, 12] = model.DInsuredSide;//受伤测
                    content[rowIndex, 13] = model.DGravitycomp;//重力补偿
                    if (IsExportParams)
                    {
                        string xmlPath = Model.AppPath.XmlDataDirPath + model.DataFileName;
                        xdoc = XDocument.Load(xmlPath);
                        List<XElement> action1 = xdoc.Descendants("action1").Elements<XElement>().ToList<XElement>();
                        List<XElement> action2 = xdoc.Descendants("action2").Elements<XElement>().ToList<XElement>();
                        for (int j = 0; j < ParamList.Count; j++)
                        {
                            int paramOneColumnIndex = j * 4;
                            double p1;
                            if (double.TryParse(action1[ParamList[j].Index].Attribute("max").Value, out p1)) {
                                //paramContent[rowIndex, paramOneColumnIndex] = p1;
                                mySheet1.Cells[rowIndex + 3, paramOneColumnIndex + testInfoColumnCount + 1] = p1;
                            }
                            double p2;
                            if (double.TryParse(action1[ParamList[j].Index].Attribute("avg").Value, out p2))
                            {
                                //paramContent[rowIndex, paramOneColumnIndex + 1] = p2;
                                mySheet1.Cells[rowIndex + 3, paramOneColumnIndex + testInfoColumnCount + 2] = p2;
                            }
                            double p3;
                            if (double.TryParse(action2[ParamList[j].Index].Attribute("max").Value, out p3))
                            {
                                //paramContent[rowIndex, paramOneColumnIndex + 2] = p3;
                                mySheet1.Cells[rowIndex + 3, paramOneColumnIndex + testInfoColumnCount + 3] = p3;
                            }
                            double p4;
                            if (double.TryParse(action2[ParamList[j].Index].Attribute("avg").Value, out p4))
                            {
                                //paramContent[rowIndex, paramOneColumnIndex + 3] = p4;
                                mySheet1.Cells[rowIndex + 3, paramOneColumnIndex + testInfoColumnCount + 4] = p4;
                            }

//.........这里部分代码省略.........
开发者ID:dewade2003,项目名称:DSJL,代码行数:101,代码来源:ExportProgressPage.xaml.cs

示例3: 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

示例4: Export

        public void Export(List<List<XElement>> datalist,string savePath)
        {
            try
            {
                excelApp = new ApplicationClass();
                Workbooks myWorkBooks = excelApp.Workbooks;
                myWorkBooks.Open(templatePath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                Sheets sheets = excelApp.Sheets;
                mySheet1 = (Worksheet)sheets[1];
                mySheet1.Activate();

                int rowCount = 1 + 2; ;//总行数

                //写入参数信息
                int paramCount = 0;//参数行数
                List<DSJL.Model.Parameter> paramList = DSJL.Model.Parameter.GetAllParams();
                paramCount = paramList.Count * 4;
                for (int i = 0; i < paramList.Count; i++)
                {
                    Model.Parameter p = paramList[i];

                    Range r = mySheet1.get_Range(mySheet1.Cells[1, testInfoColumnCount + i * 4 + 1], mySheet1.Cells[1, testInfoColumnCount + i * 4 + 4]);
                    r.Merge();
                    r.Value = p.ParamName;
                    r.Font.Bold = true;
                    r.HorizontalAlignment = XlHAlign.xlHAlignCenter;
                    r.VerticalAlignment = XlHAlign.xlHAlignCenter;

                    Range r1 = mySheet1.get_Range(mySheet1.Cells[2, testInfoColumnCount + i * 4 + 1], mySheet1.Cells[2, testInfoColumnCount + i * 4 + 4]);
                    r1.Value2 = paramContents;
                    r1.Font.Bold = true;

                    r1.EntireColumn.AutoFit();
                }

                //写入测试信息
                string[,] content = new string[rowCount, testInfoColumnCount + paramCount];
                //double?[,] paramContent = new double?[rowCount, paramCount];

                BLL.TB_Dict dictBLL = new BLL.TB_Dict();

                int rowIndex = 0;

                //content[rowIndex, 0] ="";//测试顺序
                //content[rowIndex, 1] = model.Ath_Name;//姓名
                //content[rowIndex, 2] = model.TestDate.ToString("yyyy-MM-dd HH:mm");//测试日期
                //content[rowIndex, 3] = model.DJoint;//测试关节
                //content[rowIndex, 4] = model.DJointSide;//测试侧
                //content[rowIndex, 5] = model.DPlane;//运动方式
                //content[rowIndex, 6] = model.DTestMode;//测试模式
                //content[rowIndex, 7] = model.MotionRange;//运动范围
                //content[rowIndex, 8] = model.Speed;//测试速度
                //content[rowIndex, 9] = model.Break;//休息时间
                //content[rowIndex, 10] = model.NOOfSets;//测试组数
                //content[rowIndex, 11] = model.NOOfRepetitions;//重复次数
                //content[rowIndex, 12] = model.DInsuredSide;//受伤测
                //content[rowIndex, 13] = model.DGravitycomp;//重力补偿

                List<XElement> action1 = datalist[0];
                List<XElement> action2 = datalist[1];
                for (int j = 0; j < paramList.Count; j++)
                {
                    int paramOneColumnIndex = j * 4;
                    double p1;
                    if (double.TryParse(action1[paramList[j].Index].Attribute("max").Value, out p1))
                    {
                        //paramContent[rowIndex, paramOneColumnIndex] = p1;
                        mySheet1.Cells[rowIndex + 3, paramOneColumnIndex + testInfoColumnCount + 1] = p1;
                    }
                    double p2;
                    if (double.TryParse(action1[paramList[j].Index].Attribute("avg").Value, out p2))
                    {
                        //paramContent[rowIndex, paramOneColumnIndex + 1] = p2;
                        mySheet1.Cells[rowIndex + 3, paramOneColumnIndex + testInfoColumnCount + 2] = p2;
                    }
                    double p3;
                    if (double.TryParse(action2[paramList[j].Index].Attribute("max").Value, out p3))
                    {
                        //paramContent[rowIndex, paramOneColumnIndex + 2] = p3;
                        mySheet1.Cells[rowIndex + 3, paramOneColumnIndex + testInfoColumnCount + 3] = p3;
                    }
                    double p4;
                    if (double.TryParse(action2[paramList[j].Index].Attribute("avg").Value, out p4))
                    {
                        //paramContent[rowIndex, paramOneColumnIndex + 3] = p4;
                        mySheet1.Cells[rowIndex + 3, paramOneColumnIndex + testInfoColumnCount + 4] = p4;
                    }

                }

                //写入测试信息
                Range range1 = mySheet1.get_Range(mySheet1.Cells[3, 1], mySheet1.Cells[rowCount, testInfoColumnCount]);
                range1.Value2 = content;

                mySheet1.SaveAs(savePath, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                myWorkBooks.Close();
                excelApp.Quit();

            }
            catch (Exception ee)
//.........这里部分代码省略.........
开发者ID:dewade2003,项目名称:DSJL,代码行数:101,代码来源:ExportData.cs

示例5: 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

示例6: ActiveSheet

		/// <summary>
		/// 激活Sheet表
		/// </summary>
		public void ActiveSheet(EnumType.SheetIndex sheetindex)
		{
			if(((Excel.Sheets)(((Excel.ApplicationClass)(app)).Worksheets)).Count < (int) sheetindex)
			{
				this.Dispose();
				throw new Exception("Sheet表不存在,请检查!");
			}
			try
			{
				ws = (excel.Worksheet)wb.Worksheets[sheetindex];
				ws.Activate();
			}
			catch
			{
				this.Dispose();
				throw new Exception("Sheet表激活错误,请检查!");
			}
			int irowcount = 0;
			app.ActiveCell.SpecialCells(Excel.XlCellType.xlCellTypeLastCell,Type.Missing).Select();
			irowcount = app.ActiveCell.Row;
			if((this.WriteType != EnumType.WriteType.ReWrite) && (irowcount > iMaxRow))
			{
				this.Dispose();
				throw new Exception("当前Sheet表已达存储上限,不能写入,请检查!");
			}
			int iSheetCount = wb.Sheets.Count ;
			for(int i = 1; i <= iSheetCount ; i++)
			{
				Excel.Worksheet wsT = (Excel.Worksheet) wb.Sheets[i];
				if(((this.m_sheetName != "") && ((this.m_sheetName != null)) && (this.m_sheetName.Trim().ToString() == wsT.Name.Trim().ToString()))
				 && (wsT.Name != ws.Name))
				{
					this.Dispose();
					throw new Exception("当前文件存在同名Sheet表,请检查!");
				}
			}
		}
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:40,代码来源:1438766350$ExcelManager.cs

示例7: Open

		/// <summary>
		/// 方法名称: Open
		/// 内容描述: 无
		/// 实现流程: 打开/连接一个excel数据文档
		/// 作    者: 林付国
		/// 日    期: 2006-5-13 16:23:23
		/// </summary>
		/// <returns></returns>
		public bool Open()
		{
			bool bolRetValue = false;
			string strPath = "";
			strPath = this.FilePath.ToString();

			if(!System.IO.File.Exists(strPath))
			{
				this.KillExcelProcess();
				throw new Exception("源文件不存在,请检查!");	
			}
			this.FileExteCheck(strPath);
			try
			{
				if(this.IsOpen == false)
				{
					wb = app.Workbooks.Open(strPath,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);
					ws = (excel.Worksheet)wb.Worksheets[1];//.get_Item(1);
					//ws = (excel.Worksheet)(wb.Sheets.Add(objOpt,objOpt,objOpt,objOpt)) ;
					ws.Activate();
				}
				bolRetValue = true;
			}
			catch
			{
				this.KillExcelProcess();
				throw new Exception("打开或连接Excel文档错误,请检查!");
			}
			return bolRetValue ;
		}
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:38,代码来源:1438766350$ExcelManager.cs

示例8: SelectSheet

        /// <summary>
        /// 选择工作表.
        /// </summary>
        /// <param name="sheetName"></param>
        public void SelectSheet(String sheetName)
        {
            // 选择工作表.
            xlSheet = (Excel.Worksheet)xlBook.Sheets.get_Item(sheetName);

            xlSheet.Activate();
        }
开发者ID:mahuidong,项目名称:my-csharp-sample,代码行数:11,代码来源:ExcelReport.cs


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