• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Excel.Worksheet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Worksheet类属于Microsoft.Office.Interop.Excel命名空间,在下文中一共展示了Worksheet类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ExpotToExcel

        public void ExpotToExcel(DataGridView dataGridView1,string SaveFilePath)
        {
            xlApp = new Excel.Application();
               xlWorkBook = xlApp.Workbooks.Add(misValue);
               xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
               int i = 0;
               int j = 0;

               for (i = 0; i <= dataGridView1.RowCount - 1; i++)
               {
               for (j = 0; j <= dataGridView1.ColumnCount - 1; j++)
               {
                   DataGridViewCell cell = dataGridView1[j, i];
                   xlWorkSheet.Cells[i + 1, j + 1] = cell.Value;
               }
               }

               xlWorkBook.SaveAs(SaveFilePath, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
               xlWorkBook.Close(true, misValue, misValue);
               xlApp.Quit();

               releaseObject(xlWorkSheet);
               releaseObject(xlWorkBook);
               releaseObject(xlApp);

               MessageBox.Show("Your file is saved" + SaveFilePath);
        }
开发者ID:MisuBeImp,项目名称:DhakaUniversityCyberCenterUserApps,代码行数:27,代码来源:CardUsageController.cs


示例2: ReadProcesses

        public void ReadProcesses()
        {
            count = 0;
            ExcelApp = new Excel.Application();
            ExcelApp.Visible = false;
            WorkBookExcel = ExcelApp.Workbooks.Open(_filePath, false); //открываем книгу

            //Читаем данные по проектам
            WorkSheetExcel = (Excel.Worksheet)WorkBookExcel.Sheets["Processes"]; //Получаем ссылку на лист Processes

            List<string> row = new List<string>();
            int n = 6;

            for (int i = 2; WorkSheetExcel.Cells[i, 1].Text.ToString() != ""; i++)
            {
                row = new List<string>();
                for (int j = 1; j < n; j++) row.Add(WorkSheetExcel.Cells[i, j].Text.ToString()); //строка массива заполняется просто суммой i и j
                Mas.Add(row); //строка добавляется в массив
                count++;
            }
            //test = WorkSheetExcel.Cells[2, 1];

            WorkBookExcel.Close(false, Type.Missing, Type.Missing);
            ExcelApp.Quit();
            GC.Collect();
        }
开发者ID:Samoykin,项目名称:TimeCounter,代码行数:26,代码来源:DataFromXls.cs


示例3: openXL

 public static void openXL(string xlp)
 {
     xla = new Excel.Application();
     xlw = xla.Workbooks.Open(xlp);
     xls = xlw.Worksheets.get_Item(1);
     xlr = xls.UsedRange;
 }
开发者ID:gluefish,项目名称:WatiX-cs-U,代码行数:7,代码来源:ExcelUtils.cs


示例4: ComExportExcel

 public ComExportExcel(string templatePath)
 {
     xlApp = new ComExcel.Application();
     xlWorkBook = xlApp.Workbooks.Open(templatePath, 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", true, false, 0, true, 1, 0);
     //xlWorkBook = xlApp.Workbooks.Open(templatePath, ReadOnly:false, Editable:true );
     xlWorkSheet = (ComExcel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
 }
开发者ID:vuchannguyen,项目名称:lg-py,代码行数:7,代码来源:ComExportExcel.cs


示例5: Sheet

 public Sheet(Excel.Worksheet _worksheet)
 {
     this.Base = _worksheet;
     this.CurrentRow = 1;
     this.CurrentCol = 1;
     this.Valid = ReadValues();
 }
开发者ID:robertvanbuiten,项目名称:cb_testautomation,代码行数:7,代码来源:Sheet.cs


示例6: InitializeExcel

 public static void InitializeExcel()
 {
     _myApp = new Excel.Application {Visible = false};
     _myBook = _myApp.Workbooks.Open(ExcelPath);
     _mySheet = (Excel.Worksheet)_myBook.Sheets[1]; // Explict cast is not required here
     _lastRow = _mySheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row;
 }
开发者ID:lilvonz,项目名称:SchoolAccountant,代码行数:7,代码来源:ExcelHelper.cs


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


示例8: Form1_Load

        //加载
        private void Form1_Load(object sender, EventArgs e)
        {

            panel1.Visible = false;
            app = new MSExcel.Application();
            app.Visible = false;

            book = app.Workbooks.Open(@"D:\template.xls");
            sheet = (MSExcel.Worksheet)book.ActiveSheet;



            //串口设置默认选择项
            cbSerial.SelectedIndex = 1;         //note:获得COM9口,但别忘修改
            cbBaudRate.SelectedIndex = 5;
            cbDataBits.SelectedIndex = 3;
            cbStop.SelectedIndex = 0;
            cbParity.SelectedIndex = 0;
            //sp1.BaudRate = 9600;

            Control.CheckForIllegalCrossThreadCalls = false;    //这个类中我们不检查跨线程的调用是否合法(因为.net 2.0以后加强了安全机制,,不允许在winform中直接跨线程访问控件的属性)
            sp1.DataReceived += new SerialDataReceivedEventHandler(sp1_DataReceived);
            //sp1.ReceivedBytesThreshold = 1;

            radio1.Checked = true;  //单选按钮默认是选中的
            rbRcvStr.Checked = true;

            //准备就绪              
            sp1.DtrEnable = true;
            sp1.RtsEnable = true;
            //设置数据读取超时为1秒
            sp1.ReadTimeout = 1000;

            sp1.Close();
        }
开发者ID:Jamescaiyy,项目名称:SerialPort,代码行数:36,代码来源:Form1.cs


示例9: ClusteringManager

        public ClusteringManager()
        {
            //prepare Excel objects:
            m_ObjExcel = new Microsoft.Office.Interop.Excel.Application();
            m_ObjWorkBook = m_ObjExcel.Workbooks.Open(
                MethodInputResponse.INPUT_FILE_PATH,
                0,
                false,
                5,
                "",
                "",
                false,
                Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,
                "",
                true,
                false,
                0,
                true,
                false,
                false);
            m_ObjWorkSheet1 = (myExcel.Worksheet)m_ObjWorkBook.Sheets[1];

            myExcel.Sheets xlSheets = m_ObjWorkBook.Sheets as myExcel.Sheets;
            for (int i = 3; i < MAX_CLUSTERS_NUMBER; i++)
            {
                xlSheets.Add(Type.Missing, m_ObjWorkSheet1, Type.Missing, Type.Missing);
            }
        }
开发者ID:osnihur,项目名称:clustering,代码行数:28,代码来源:ClusteringManager.cs


示例10: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            MyApp = new Excel.Application();
            MyApp.Visible = false;
            MyBook = MyApp.Workbooks.Open(path);
            MySheet = (Excel.Worksheet)MyBook.Sheets[1];
            lastrow = MySheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row;

            BindingList<Dompet> DompetList = new BindingList<Dompet>();

            for (int index = 2; index <= lastrow; index++)
            {
                System.Array MyValues = 
                    (System.Array)MySheet.get_Range
                    ("A" + index.ToString(),"F" + index.ToString()).Cells.Value;
                DompetList.Add(new Dompet {
                    JmlPemesanan = MyValues.GetValue(1,1).ToString(),
                    JmlPekerja = MyValues.GetValue(1,2).ToString(),
                    Peralatan = MyValues.GetValue(1,3).ToString(),
                    JenisKulit = MyValues.GetValue(1,4).ToString(),
                    ModelDompet = MyValues.GetValue(1,5).ToString(),
                    Prediksi = MyValues.GetValue(1,6).ToString()
                });
            }
            dataGridView1.DataSource = (BindingList<Dompet>)DompetList;
            dataGridView1.AutoResizeColumns();
        }
开发者ID:renandatta,项目名称:NaiveBayes,代码行数:27,代码来源:FrmMain.cs


示例11: TaskPriority

        public TaskPriority()
        {
            InitializeComponent();
            missing = System.Reflection.Missing.Value;
            config_data.ConfigFile = Environment.GetEnvironmentVariable("USERPROFILE")+"\\IntCallBack.xls";
            xlApp = new msexcel.Application();
            time_wasting = false;

            if (File.Exists(config_data.ConfigFile))
            {
                xlWorkBook = xlApp.Workbooks.Open(config_data.ConfigFile, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                xlWorkSheet = (msexcel.Worksheet) xlWorkBook.Worksheets.get_Item(1);

                double dummy = (double) (xlWorkSheet.Cells[1, 2] as msexcel.Range ).Value ;
                config_data.PopUp = ((int)dummy == 1) ? true : false;
                config_data.RFrequency = (int)(xlWorkSheet.Cells[2, 2] as msexcel.Range).Value;
                config_data.Urgent_Hrs = (int)(xlWorkSheet.Cells[3, 2] as msexcel.Range).Value;
                config_data.Urgent_Mins = (int)(xlWorkSheet.Cells[4, 2] as msexcel.Range).Value;
                config_data.task1 = (string) (xlWorkSheet.Cells[5, 2] as msexcel.Range).Value;
                config_data.task2 = (string)(xlWorkSheet.Cells[6, 2] as msexcel.Range).Value;
                config_data.task3 = (string)(xlWorkSheet.Cells[7, 2] as msexcel.Range).Value;
                config_data.task4 = (string)(xlWorkSheet.Cells[8, 2] as msexcel.Range).Value;
                re_load_flag = true;

            }
            else
            {

                xlWorkBook = xlApp.Workbooks.Add(missing);
                xlWorkSheet = xlWorkBook.Worksheets.get_Item(1);

                config_data.PopUp = true;
                config_data.RFrequency = 3;
                config_data.Urgent_Hrs = 8;
                config_data.Urgent_Mins = 0;
                config_data.task1 = config_data.task2 = config_data.task3 = config_data.task4 = "";

                xlWorkSheet.Cells[1, 1] = "PopUP";
                xlWorkSheet.Cells[2, 1] = "Frequency";
                xlWorkSheet.Cells[3, 1] = "Urgent Hrs";
                xlWorkSheet.Cells[4, 1] = "Urgent Mins";
                xlWorkSheet.Cells[5,1] = "Task 1";
                xlWorkSheet.Cells[6,1] = "Task 2";
                xlWorkSheet.Cells[7,1] = "Task 3";
                xlWorkSheet.Cells[8,1] = "Task 4";

                xlWorkSheet.Cells[1, 2] = (config_data.PopUp == true) ? "1" : "2";
                xlWorkSheet.Cells[2, 2] = config_data.RFrequency.ToString();
                xlWorkSheet.Cells[3, 2] = config_data.Urgent_Hrs.ToString();
                xlWorkSheet.Cells[4, 2] = config_data.Urgent_Mins.ToString();
                xlWorkSheet.Cells[5, 2] = config_data.task1;
                xlWorkSheet.Cells[6, 2] = config_data.task1;
                xlWorkSheet.Cells[7, 2] = config_data.task1;
                xlWorkSheet.Cells[8, 2] = config_data.task1;

                xlWorkBook.SaveAs(config_data.ConfigFile, msexcel.XlFileFormat.xlWorkbookNormal, missing, missing, missing, missing, msexcel.XlSaveAsAccessMode.xlShared, missing, missing, missing, missing, missing);
                //xlWorkBook.Close();
                re_load_flag = false;
            }
        }
开发者ID:Dhilip-Kumar-S,项目名称:InterruptCallBack,代码行数:60,代码来源:Form1.cs


示例12: ReportGenerator

        public ReportGenerator(Excel.Worksheet src_worksheet, Excel.Worksheet dest_worksheet)
        {
            _src_worksheet = src_worksheet;
            _dest_worksheet = dest_worksheet;

            writeProjectNamesToDestSheet();
        }
开发者ID:Jeff-Eu,项目名称:WeeklyReportGenerator,代码行数:7,代码来源:ReportGenerator.cs


示例13: Init

        private void Init()
        {
            xlApp = new Excel.Application();

            xlWorkBook = xlApp.Workbooks.Open(name, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            xlSh = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
        }
开发者ID:NextStalker,项目名称:RegionalReport,代码行数:7,代码来源:OfficeDoc.cs


示例14: OrderingSheet

        internal OrderingSheet(bool isUnscheduled)
        {
            if (!Globals.DataSet.IsLastDayComplete())
            {
                throw new ApplicationException(Globals.ThisWorkbook.IncompleteDataMessage);
            }

            this.orderDate = Globals.DataSet.MaxDate;

            string worksheetName;

            if (isUnscheduled)
            {
                worksheetName = ExcelHelpers.CreateValidWorksheetName(
                    String.Format(
                        CultureInfo.CurrentUICulture,
                        Properties.Resources.UnscheduledOrderSheetName,
                        this.orderDate.ToShortDateString()));
            }
            else
            {
                worksheetName = ExcelHelpers.CreateValidWorksheetName(
                    String.Format(
                        CultureInfo.CurrentUICulture,
                        Properties.Resources.WeeklyOrderSheetName,
                        this.orderDate.ToShortDateString()));
            }
            Excel.Worksheet worksheet = null;

            // 如果该名称已经存在,则在创建工作表时将引发异常。
            try
            {
                worksheet = Globals.ThisWorkbook.CreateWorksheet(worksheetName);
            }
            catch (Exception ex)
            {
                string message;

                if (isUnscheduled)
                {
                    message = String.Format(
                        CultureInfo.CurrentUICulture,
                        Properties.Resources.UnscheduledOrderSheetCreationError,
                        worksheetName);
                }
                else
                {
                    message = String.Format(
                        CultureInfo.CurrentUICulture,
                        Properties.Resources.WeeklyOrderSheetCreationError,
                        worksheetName);
                }

                throw new ApplicationException(message, ex);
            }

            this.worksheet = worksheet;

            CreateOrder(isUnscheduled);
        }
开发者ID:jetlive,项目名称:skiaming,代码行数:60,代码来源:orderingsheet.cs


示例15: createWorksheet

        /// <summary>
        /// Creates a spreadsheet in the give xls filename. 
        /// </summary>
        /// <param name="filename">The complete filename with the absolute path.</param>
        /// <param name="sheetname">The name of the sheet e.g. Hidden</param>
        /// <returns>True if succeeded, false if failed.</returns>
        public static bool createWorksheet(String filename, String sheetname, bool needsToBeHidden = false)
        {
            successStatus = false;
            try
            {
                successStatus = openXlApp();
                CurrentSpreadSheet css = CurrentSpreadSheet.Instance;
                //checking if the call is being made for the currently open worbook. this is less expensive.
                if ((css.CurrentWorkBook != null) && (css.CurrentWorkBook.FullName == filename))
                {
                    xlSheets = css.CurrentWorkBook.Sheets as Excel.Sheets;
                }
                else
                {
                    xlWorkbook = openXlWorkBook(filename);
                    xlSheets = xlWorkbook.Sheets as Excel.Sheets;
                }

                xlSheet = (Excel.Worksheet)xlSheets.Add(xlSheets[xlSheets.Count + 1]);
                xlSheet.Name = sheetname;

                if (needsToBeHidden) xlSheet.Visible = Excel.XlSheetVisibility.xlSheetHidden;

                xlWorkbook.Save();
                successStatus = quitXlApp();
            }
            finally
            {
                garbageCollect();
            }

            return successStatus;
        }
开发者ID:risavkarna,项目名称:Sally,代码行数:39,代码来源:Alex_API.cs


示例16: Matrix_Worksheet

        public Matrix_Worksheet(Matrix_Workbook matrixWorkbook, Microsoft.Office.Interop.Excel.Worksheet workSheet)
        {
            _matrixWorkbook = matrixWorkbook;
            _worksheet = workSheet;

            InitializeControlData();
        }
开发者ID:jimbrannon,项目名称:tlap_p2jm,代码行数:7,代码来源:Matrix_Worksheet.cs


示例17: ExcelBase

        /// <summary>
        /// 构造函数,将一个已有Excel工作簿作为模板,并指定输出路径
        /// </summary>
        /// <param name="templetFilePath">Excel模板文件路径</param>
        /// <param name="outputFilePath">输出Excel文件路径</param>
        public ExcelBase(string templetFilePath, string outputFilePath)
        {
            if (templetFilePath == null)
                throw new Exception("Excel模板文件路径不能为空!");

            if (outputFilePath == null)
                throw new Exception("输出Excel文件路径不能为空!");

            if (!File.Exists(templetFilePath))
                throw new Exception("指定路径的Excel模板文件不存在!");

            this.templetFile = templetFilePath;
            this.outputFile = outputFilePath;

            //创建一个Application对象并使其可见
            beforeTime = DateTime.Now;
            app = new Excel.ApplicationClass();
            app.Visible = true;
            afterTime = DateTime.Now;

            //打开模板文件,得到WorkBook对象
            workBook = app.Workbooks.Open(templetFile, missing, missing, missing, missing, missing,
             missing, missing, missing, missing, missing, missing, missing);

            //得到WorkSheet对象
            workSheet = (Excel.Worksheet)workBook.Sheets.get_Item(1);
        }
开发者ID:ramic,项目名称:ramic,代码行数:32,代码来源:ExcelBase.cs


示例18: readData

        public getData readData()
        {
            getData.dateT.Clear();
            getData.prj.Clear();
            getData.descr.Clear();
            getData.taskTime.Clear();
            notes.Clear();
            ExcelApp = new Excel.Application();
            ExcelApp.Visible = false;
            WorkBookExcel = ExcelApp.Workbooks.Open(_filePath, false); //открываем книгу
            WorkSheetExcel = (Excel.Worksheet)WorkBookExcel.Sheets[1]; //Получаем ссылку на лист 1

            //excelcells = excelworksheet.get_Range("D215", Type.Missing); //Выбираем ячейку для вывода A1
            // WorkSheetExcel.Cells[i, 1].Text.ToString() != ""

            for (int i = 2; WorkSheetExcel.Cells[i, 1].Text.ToString() != ""; i++)
            {

                getData.dateT.Add(WorkSheetExcel.Cells[i, 1].Text.ToString());
                getData.prj.Add(WorkSheetExcel.Cells[i, 2].Text.ToString());
                getData.descr.Add(WorkSheetExcel.Cells[i, 3].Text.ToString());
                getData.taskTime.Add(WorkSheetExcel.Cells[i, 4].Text.ToString());
            }

            WorkBookExcel.Close(false, Type.Missing, Type.Missing); //закрыл не сохраняя
            ExcelApp.Quit();
            GC.Collect();

            getData.dateT.Reverse();
            getData.prj.Reverse();
            getData.descr.Reverse();
            getData.taskTime.Reverse();

            return getData;
        }
开发者ID:Samoykin,项目名称:TimeCounter,代码行数:35,代码来源:ReadWorkList.cs


示例19: export

        public void export()
        {
            try
            {

                //excelApp = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
                //wb = excelApp.Workbooks.Add();
                wb = (Excel.Workbook)Globals.ThisAddIn.Application.ActiveWorkbook;
                ws = wb.Worksheets.get_Item(1) as Excel.Worksheet;

                // 데이타 넣기
                int r = 1;
                foreach (var d in this.exceptionList_)
                {
                    ws.Cells[r, 1] = d.Message;
                    r++;
                }

                //this.wb.Worksheets.Add(ws);
            }
            finally 
            {
                // Clean up
                ReleaseExcelObject(ws);
                ReleaseExcelObject(wb);
                ReleaseExcelObject(excelApp);
            }
        }
开发者ID:minikie,项目名称:test,代码行数:28,代码来源:ExcelExport.cs


示例20: BadTaskSpecExtractionAndTaskFactoryParsingTest

        public void BadTaskSpecExtractionAndTaskFactoryParsingTest()
        {
            ws = (Excel.Worksheet)wss["TestTasks2"];

            IEnumerable<Specification> actualTaskSpecs;
            Assert.IsFalse(excelController.ExtractData(out actualTaskSpecs));
        }
开发者ID:DeStuderendesErhvervskontakt,项目名称:ProjectPlanner,代码行数:7,代码来源:IntegrationExcelControllerTaskFactory.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Outlook.Application类代码示例发布时间:2022-05-26
下一篇:
C# Excel.Workbook类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap