Beispiel #1
0
 public static List<ExcelHeader> get2Headers(Worksheet xlWs, object[,] ExcelData, int startRow)
 {
     List<ExcelHeader> list = new List<ExcelHeader>();
     string str = string.Empty;
     for (int i = ExcelData.GetLowerBound(1); i <= ExcelData.GetUpperBound(1); i++)
     {
         if (ExcelData[startRow - 1, i] != null)
         {
             string str2 = string.Empty;
             string str3 = ExcelData[startRow - 1, i].ToString();
             if (ExcelData[startRow - 2, i] != null)
             {
                 str2 = ExcelData[startRow - 2, i].ToString();
                 if ((xlWs.Cells[startRow - 2, i].MergeArea.Cells.Count > 1) || (((XlHAlign) xlWs.Cells[startRow - 2, i].HorizontalAlignment) == XlHAlign.xlHAlignCenterAcrossSelection))
                 {
                     str = str2;
                 }
                 else
                 {
                     str = string.Empty;
                 }
             }
             else if ((xlWs.Cells[startRow - 2, i].MergeArea.Cells.Count > 1) || (((XlHAlign) xlWs.Cells[startRow - 2, i].HorizontalAlignment) == XlHAlign.xlHAlignCenterAcrossSelection))
             {
                 str2 = str;
             }
             list.Add(new ExcelHeader(str2, str3, i));
         }
     }
     xlWs.DisposeChildInstances();
     return list;
 }
Beispiel #2
0
 private static void Thread3Method(object mre)
 {
     Excel.Worksheet sheet = _application.ActiveSheet as Excel.Worksheet;
     foreach (Excel.Range range in sheet.Range("A1:B200"))
     {
         Excel.Workbook book = range.Application.ActiveWorkbook;
         foreach (object item in book.Sheets)
         {
             Excel.Worksheet otherSheet = item as Excel.Worksheet;
             Excel.Range     rng        = otherSheet.Cells[1, 1];
         }
     }
     sheet.DisposeChildInstances();
     (mre as ManualResetEvent).Set();
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("NetOffice Release Performance Test - 15000 Cells.");
            Console.WriteLine("Write simple text, change Font, NumberFormat, WrapText and add a comment.");

            // start excel, and get a new sheet reference
            Excel.Application excelApplication = CreateExcelApplication();
            Excel.Worksheet   sheet            = excelApplication.Workbooks.Add().Worksheets.Add() as Excel.Worksheet;

            // do test 10 times
            List <TimeSpan> timeElapsedList = new List <TimeSpan>();

            for (int i = 1; i <= 10; i++)
            {
                sheet.UsedRange.ClearComments();
                DateTime timeStart = DateTime.Now;
                for (int y = 1; y <= 15000; y++)
                {
                    string      rangeAdress = "$A" + y.ToString();
                    Excel.Range cellRange   = sheet.get_Range(rangeAdress);
                    cellRange.Value        = "value";
                    cellRange.Font.Name    = "Verdana";
                    cellRange.NumberFormat = "@";
                    cellRange.WrapText     = true;
                    cellRange.AddComment("Sample Comment");
                }
                TimeSpan timeElapsed = DateTime.Now - timeStart;

                // display info and dispose references
                Console.WriteLine("Time Elapsed: {0}", timeElapsed);
                timeElapsedList.Add(timeElapsed);
                sheet.DisposeChildInstances();
            }

            // display info & log to file
            TimeSpan timeAverage = AppendResultToLogFile(timeElapsedList, "Test3-NetOffice.log");

            Console.WriteLine("Time Average: {0}{1}Press any key...", timeAverage, Environment.NewLine);
            Console.Read();

            // release & quit
            excelApplication.Quit();
            excelApplication.Dispose();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("NetOffice Release Performance Test - 10000 Cells.");
            Console.WriteLine("Write simple text, change Font, NumberFormat and do a BorderArround.");

            // start excel, and get a new sheet reference
            Excel.Application excelApplication = CreateExcelApplication();
            Excel.Worksheet   sheet            = excelApplication.Workbooks.Add().Worksheets.Add() as Excel.Worksheet;

            // do test 10 times
            List <TimeSpan> timeElapsedList = new List <TimeSpan>();

            for (int i = 1; i <= 10; i++)
            {
                DateTime timeStart = DateTime.Now;
                for (int y = 1; y <= 10000; y++)
                {
                    string      rangeAdress = "$A" + y.ToString();
                    Excel.Range cellRange   = sheet.get_Range(rangeAdress);
                    cellRange.Value        = "value";
                    cellRange.Font.Name    = "Verdana";
                    cellRange.NumberFormat = "@";
                    cellRange.BorderAround(XlLineStyle.xlDouble, XlBorderWeight.xlMedium, XlColorIndex.xlColorIndexAutomatic, 0);
                }
                TimeSpan timeElapsed = DateTime.Now - timeStart;

                // display info and dispose references
                Console.WriteLine("Time Elapsed: {0}", timeElapsed);
                timeElapsedList.Add(timeElapsed);
                sheet.DisposeChildInstances();
            }

            // display info & log to file
            TimeSpan timeAverage = AppendResultToLogFile(timeElapsedList, "Test2-NetOffice.log");

            Console.WriteLine("Time Average: {0}{1}Press any key...", timeAverage, Environment.NewLine);
            Console.Read();

            // release & quit
            excelApplication.Quit();
            excelApplication.Dispose();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("NetOffice Release 1.3 Performance Test - 5000 Cells.");
            Console.WriteLine("Write simple text.");

            // start excel, and get a new sheet reference
            Excel.Application excelApplication = CreateExcelApplication();
            Excel.Worksheet   sheet            = excelApplication.Workbooks.Add().Worksheets.Add() as Excel.Worksheet;

            // do test 10 times
            List <TimeSpan> timeElapsedList = new List <TimeSpan>();

            for (int i = 1; i <= 10; i++)
            {
                DateTime timeStart = DateTime.Now;
                for (int y = 1; y <= 5000; y++)
                {
                    string rangeAdress = "$A" + y.ToString();
                    sheet.get_Range(rangeAdress).Value = "value";
                }
                TimeSpan timeElapsed = DateTime.Now - timeStart;

                // display info and dispose references
                Console.WriteLine("Time Elapsed: {0}", timeElapsed);
                timeElapsedList.Add(timeElapsed);
                sheet.DisposeChildInstances();
            }

            // display info & log to file
            TimeSpan timeAverage = AppendResultToLogFile(timeElapsedList, "Test1-NetOffice.log");

            Console.WriteLine("Time Average: {0}{1}Press any key...", timeAverage, Environment.NewLine);
            Console.Read();

            // release & quit
            excelApplication.Quit();
            excelApplication.Dispose();
        }
Beispiel #6
0
 public static void writeColumn(Worksheet xlWs, object[] Column, int ColumnNo, int startRow)
 {
     try
     {
         object[,] objArray = new object[Column.Length, 1];
         for (int i = 0; i < Column.Length; i++)
         {
             objArray[i, 0] = Column[i];
         }
         Range range = xlWs.Cells[startRow, ColumnNo];
         Range range2 = xlWs.Cells[startRow + objArray.GetUpperBound(0), ColumnNo];
         xlWs.Range(range, range2).Value2 = objArray;
         xlWs.DisposeChildInstances();
     }
     catch
     {
     }
 }
Beispiel #7
0
 public static void writeRow(Worksheet xlWs, Dictionary<int, object> rowData, int tgtRow)
 {
     try
     {
         foreach (KeyValuePair<int, object> pair in rowData)
         {
             Range range = xlWs.Cells[tgtRow, pair.Key];
             range.Value2 = pair.Value;
         }
         xlWs.DisposeChildInstances();
     }
     catch
     {
     }
 }