Esempio n. 1
0
        /// <summary>
        /// 测试 读写.
        /// </summary>
        public void TestReadWrite()
        {
            Console.WriteLine("测试 Excel 读写 开始!");

            string fileName =
                System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
                + @"ExcelFiles\测试读写.xls";

            ExcelReport service = new ExcelReport();

            // 打开 Excel.
            service.OpenExcel();

            // 打开 Excel 文件.
            service.OpenExcelFile(fileName);

            // 选择工作表.
            service.SelectSheet("测试读写");

            for (int i = 2; i <= 5; i++)
            {
                // 获取数据.
                Console.WriteLine("{0}.{1}.{2}.{3}",
                    service.GetValue(i, 1),
                    service.GetValue(i, 2),
                    service.GetValue(i, 3),
                    service.GetValue(i, 4));

                // 设置公式.
                service.SetFormulaR1C1(i, 5, "=IF(测试读写!R" + i + "C4>=18,\"18+\",\"未成年\")");

                // 设置数值.
                service.SetValue(i, 6, "Test" + i);
            }

            // 保存 Excel 文件.
            service.SaveExcelFile();

            // 关闭 Excel.
            service.CloseExcel();

            Console.WriteLine("测试 Excel 读写 结束!");
        }