using System;
using System.Collections;
using System.Data;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Excel;
using QC.CorpTest.Libraries.ExcelLibrary;

namespace QTMDataFormat;

public class ExcelFunctions
{
	public class CellPosition
	{
		private int localRow = -1;

		private int localColumn = -1;

		public int Row
		{
			get
			{
				return localRow;
			}
			set
			{
				localRow = value;
			}
		}

		public int Column
		{
			get
			{
				return localColumn;
			}
			set
			{
				localColumn = value;
			}
		}

		public bool IsValid
		{
			get
			{
				if (localRow == -1 && localColumn == -1)
				{
					return false;
				}
				return true;
			}
		}

		public CellPosition(int row, int column)
		{
			localRow = row;
			localColumn = column;
		}

		public CellPosition()
		{
		}
	}

	public class TemplateSheetInfo
	{
		public const int DataStartBufferRows = 2;

		private CellPosition templateStartCell = new CellPosition();

		private CellPosition templateEndCell = new CellPosition();

		private CellPosition lowerLimitCell = new CellPosition();

		private CellPosition upperLimitCell = new CellPosition();

		private CellPosition dataStartCell = new CellPosition();

		private CellPosition dataEndCell = new CellPosition();

		public CellPosition TemplateStartCell
		{
			get
			{
				return templateStartCell;
			}
			set
			{
				templateStartCell = value;
			}
		}

		public CellPosition TemplateEndCell
		{
			get
			{
				return templateEndCell;
			}
			set
			{
				templateEndCell = value;
			}
		}

		public CellPosition UpperLimitCell
		{
			get
			{
				return upperLimitCell;
			}
			set
			{
				upperLimitCell = value;
			}
		}

		public CellPosition LowerLimitCell
		{
			get
			{
				return lowerLimitCell;
			}
			set
			{
				lowerLimitCell = value;
			}
		}

		public CellPosition DataStartCell
		{
			get
			{
				return dataStartCell;
			}
			set
			{
				dataStartCell = value;
			}
		}

		public CellPosition DataEndCell
		{
			get
			{
				return dataEndCell;
			}
			set
			{
				dataEndCell = value;
			}
		}
	}

	public struct ChartDataDetails
	{
		public string ChartParamName;

		public string ChartTestName;

		public string ChartCondName;

		public string ChartInnerLoop;

		public int StartCol;

		public int StopCol;
	}

	public struct structRangeProperty
	{
		public object WrapText;

		public object ColumnWidth;

		public object HorizontalAlignment;

		public object VerticalAlignment;

		public object LineStyle;
	}

	public struct HighlightDataLong
	{
		public int DataStartRow;

		public int ValueCol;

		public Worksheet InputSheet;

		public Application oExcel;
	}

	public struct HighlightDataWide
	{
		public structRangeProperty defProperty;

		public int DataStartCol;

		public int DataEndCol;

		public int DataEndRow;

		public Worksheet InputSheet;

		public Application oExcel;

		public int DataRow;

		public int LLRow;

		public int ULRow;
	}

	public class structDataSeries
	{
		private string dataseriesname;

		private string dataseriesvalue;

		public string Name
		{
			get
			{
				return dataseriesname;
			}
			set
			{
				dataseriesname = value;
			}
		}

		public string Values
		{
			get
			{
				return dataseriesvalue;
			}
			set
			{
				dataseriesvalue = value;
			}
		}

		public structDataSeries(string seriesname, Range valuerange)
		{
			dataseriesname = seriesname;
			dataseriesvalue = "=" + valuerange[(object)true, (object)true, (XlReferenceStyle)(-4150), (object)true, (object)false];
		}

		public structDataSeries(string seriesname, string csvseriesvalue)
		{
			dataseriesname = seriesname;
			dataseriesvalue = "={" + csvseriesvalue + "}";
		}
	}

	public class BoxWhiskerData
	{
		public structDataSeries Quartlie1Series;

		public structDataSeries MinSeries;

		public structDataSeries MedianSeries;

		public structDataSeries MaxSeries;

		public structDataSeries Quartlie3Series;

		public structDataSeries MeanSeries;

		public structDataSeries UpperLimit;

		public structDataSeries LowerLimit;

		public string CategoryXLabels;

		public string ChartTitle;

		public string YAxisTitle;

		public Workbook CurrentWorkBook;

		public Worksheet CurrentWorkSheet;

		public int HeightPoint;

		public int WidthPoint;

		public int TopPoint;

		public int LeftPoint;

		public double MaximumScale;

		public double MinimumScale;

		public double StepSize;

		public int NumberOfPlots;
	}

	private const int MAX_CELL = 1048576;

	private const int maximumExcelRows = 1048576;

	private const int maximumExcelColumns = 16384;

	public static bool ExportArrayDataToExcel(string[,] ArrayInput, int NumCols, int NumRows, bool showExcel, out string warnstring)
	{
		warnstring = "";
		Application oExcel = null;
		Workbook theWorkbook = null;
		if (!OpenExcelWithWorkBook(ref oExcel, "c:\\temp\\FormatExcel.xls", out theWorkbook, showExcel, out warnstring))
		{
			warnstring = "Error Exporting Array To Excel: " + warnstring;
			return false;
		}
		return true;
	}

	public static bool MapPresent(ref Application oExcel, string MapName)
	{
		bool result = false;
		XmlMap val = null;
		if (((_Workbook)((_Application)oExcel).ActiveWorkbook).XmlMaps.Count > 0)
		{
			XmlMaps xmlMaps = ((_Workbook)((_Application)oExcel).ActiveWorkbook).XmlMaps;
			for (int i = 1; i <= xmlMaps.Count; i++)
			{
				val = xmlMaps[(object)i];
				if (val.Name == MapName)
				{
					result = true;
					break;
				}
			}
		}
		return result;
	}

	public static bool OpenExcelWithXmlData(string SheetName, string WorkBookName, string XmlFileName, bool hasDummyRow, bool showExcel, bool closeExcelAfterExport, out string warnstring)
	{
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Expected O, but got Unknown
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Expected O, but got Unknown
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		warnstring = "";
		Application oExcel = null;
		Workbook theWorkbook = null;
		Worksheet val = null;
		string warnstring2 = "";
		if (XmlFileName.Trim().Length == 0)
		{
			XmlFileName = "\\temp\\formatxml.xml";
		}
		if (SheetName.Trim().Length == 0)
		{
			SheetName = "test";
		}
		if (WorkBookName.Trim().Length == 0)
		{
			WorkBookName = "c:\\temp\\FormatExcel.xls";
		}
		try
		{
			if (!OpenExcelWithWorkBook(ref oExcel, WorkBookName, out theWorkbook, showExcel, out warnstring2))
			{
				warnstring = "Error Opening workbook - " + warnstring2;
				return false;
			}
			val = (Worksheet)((_Workbook)theWorkbook).Sheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
			((_Application)oExcel).DisplayAlerts = false;
			XmlMap val2 = default(XmlMap);
			((_Workbook)((_Application)oExcel).ActiveWorkbook).XmlImport(XmlFileName, ref val2, (object)false, (object)((_Worksheet)val)[(object)"A5", Type.Missing]);
			try
			{
				((_Worksheet)val).Name = SheetName;
			}
			catch
			{
			}
			val2.Name = ((_Worksheet)val).Name;
			Range val3;
			if (hasDummyRow)
			{
				val3 = (Range)((_Worksheet)val).Cells[(object)6, (object)1];
				val3.EntireRow.Delete((object)true);
			}
			((_Workbook)((_Application)oExcel).ActiveWorkbook).Save();
			val3 = ((_Worksheet)val)[(object)"A5", Type.Missing];
			Range usedRange = ((_Worksheet)val).UsedRange;
			val3.EntireRow.WrapText = true;
			((_Application)oExcel).DisplayAlerts = true;
			((_Workbook)((_Application)oExcel).ActiveWorkbook).Save();
			CleanUpExcelObjects(val2, val3, usedRange, val, ((_Application)oExcel).ActiveWorkbook, oExcel, closeExcelAfterExport);
		}
		catch (Exception ex)
		{
			warnstring = "Error opening XML Data with OpenExcelWithXmlData():" + ex.Message;
			try
			{
				((_Workbook)((_Application)oExcel).ActiveWorkbook).Save();
				((_Application)oExcel).DisplayAlerts = true;
			}
			catch
			{
			}
			return false;
		}
		return true;
	}

	public static bool OpenExcelWithXmlData(string SheetName, string WorkBookName, string XmlFileName, bool hasDummyRow, bool showExcel, bool closeExcelAfterExport, int startRow, int startCol, out string warnstring)
	{
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Expected O, but got Unknown
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Expected O, but got Unknown
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Expected O, but got Unknown
		warnstring = "";
		Application oExcel = null;
		Workbook theWorkbook = null;
		Worksheet objWorkSheet = null;
		string warnstring2 = "";
		if (XmlFileName.Trim().Length == 0)
		{
			XmlFileName = "\\temp\\formatxml.xml";
		}
		if (SheetName.Trim().Length == 0)
		{
			SheetName = "test";
		}
		if (WorkBookName.Trim().Length == 0)
		{
			WorkBookName = "c:\\temp\\FormatExcel.xls";
		}
		try
		{
			if (!OpenExcelWithWorkBook(ref oExcel, WorkBookName, out theWorkbook, showExcel, out warnstring2))
			{
				warnstring = "Error Opening workbook - " + warnstring2;
				return false;
			}
			if (!SheetExists(SheetName, ref theWorkbook, ref objWorkSheet, out warnstring2))
			{
				objWorkSheet = (Worksheet)((_Workbook)theWorkbook).Sheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
				try
				{
					((_Worksheet)objWorkSheet).Name = SheetName;
				}
				catch
				{
				}
			}
			((_Application)oExcel).DisplayAlerts = false;
			XmlMap xMap = default(XmlMap);
			((_Workbook)((_Application)oExcel).ActiveWorkbook).XmlImport(XmlFileName, ref xMap, (object)false, (object)(Range)((_Worksheet)objWorkSheet).Cells[(object)startRow, (object)startCol]);
			Range val;
			if (hasDummyRow)
			{
				val = (Range)((_Worksheet)objWorkSheet).Cells[(object)6, (object)1];
				val.EntireRow.Delete((object)true);
			}
			((_Workbook)((_Application)oExcel).ActiveWorkbook).Save();
			val = ((_Worksheet)objWorkSheet)[(object)"A5", Type.Missing];
			Range usedRange = ((_Worksheet)objWorkSheet).UsedRange;
			val.EntireRow.WrapText = true;
			((_Application)oExcel).DisplayAlerts = true;
			((_Workbook)((_Application)oExcel).ActiveWorkbook).Save();
			CleanUpExcelObjects(xMap, val, usedRange, objWorkSheet, ((_Application)oExcel).ActiveWorkbook, oExcel, closeExcelAfterExport);
		}
		catch (Exception ex)
		{
			warnstring = "Error opening XML Data with OpenExcelWithXmlData():" + ex.Message;
			try
			{
				((_Workbook)((_Application)oExcel).ActiveWorkbook).Save();
				((_Application)oExcel).DisplayAlerts = true;
			}
			catch
			{
			}
			return false;
		}
		return true;
	}

	public static bool ImportXmlinExcelWithoutStats(string SheetName, string WorkBookName, string XmlFileName, int NumResultCol, bool DoHighlight, bool hasDummyRow, bool showExcel, bool closeExcelAfterExport, out string warnstring)
	{
		warnstring = "";
		string warnstring2 = "";
		Application val = null;
		try
		{
			if (!OpenExcelWithXmlData(SheetName, WorkBookName, XmlFileName, hasDummyRow, showExcel, closeExcelAfterExport, out warnstring2))
			{
				warnstring = "Error in Importing XML without Stats:" + warnstring2;
				return false;
			}
			return true;
		}
		catch (Exception ex)
		{
			warnstring = "Error Importing XML without Stats: " + ex.Message;
			try
			{
				((_Workbook)((_Application)val).ActiveWorkbook).Save();
			}
			catch
			{
			}
			return false;
		}
	}

	public static void HighlightRowsInLongView(object InputValues)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Expected O, but got Unknown
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Expected O, but got Unknown
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Expected O, but got Unknown
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Unknown result type (might be due to invalid IL or missing references)
		HighlightDataLong highlightDataLong = (HighlightDataLong)InputValues;
		try
		{
			Worksheet inputSheet = highlightDataLong.InputSheet;
			int num = highlightDataLong.ValueCol - 1;
			int num2 = highlightDataLong.ValueCol + 1;
			inputSheet = (Worksheet)((_Application)highlightDataLong.oExcel).ActiveSheet;
			Range val = (Range)((_Worksheet)inputSheet).Cells[(object)highlightDataLong.DataStartRow, (object)highlightDataLong.ValueCol];
			val = val[(XlDirection)(-4121)];
			int row = val.Row;
			int valueCol = highlightDataLong.ValueCol;
			for (int i = highlightDataLong.DataStartRow; i <= row; i++)
			{
				val = (Range)((_Worksheet)inputSheet).Cells[(object)i, (object)valueCol];
				Range val2 = (Range)((_Worksheet)inputSheet).Cells[(object)i, (object)num];
				string text = val2[(object)i, (object)num, (XlReferenceStyle)1, Type.Missing, Type.Missing];
				Range val3 = (Range)((_Worksheet)inputSheet).Cells[(object)i, (object)num2];
				string text2 = val3[(object)i, (object)num2, (XlReferenceStyle)1, Type.Missing, Type.Missing];
				string text3 = (string)val.Text;
				if (text3.Length != 0 && double.TryParse(text3, NumberStyles.Any, null, out var _))
				{
					val.FormatConditions.Add((XlFormatConditionType)1, (object)(XlFormatConditionOperator)2, (object)("=" + text), (object)("=" + text2), Type.Missing, Type.Missing, Type.Missing, Type.Missing);
					((FormatCondition)val.FormatConditions[(object)1]).Interior.ColorIndex = 3;
					val.FormatConditions.Add((XlFormatConditionType)1, (object)(XlFormatConditionOperator)3, (object)("=" + text), Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
					((FormatCondition)val.FormatConditions[(object)2]).Interior.ColorIndex = 6;
					val.FormatConditions.Add((XlFormatConditionType)1, (object)(XlFormatConditionOperator)3, (object)("=" + text2), Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
					((FormatCondition)val.FormatConditions[(object)3]).Interior.ColorIndex = 6;
				}
			}
			((_Workbook)((_Application)highlightDataLong.oExcel).ActiveWorkbook).Save();
		}
		catch
		{
			try
			{
				((_Workbook)((_Application)highlightDataLong.oExcel).ActiveWorkbook).Save();
			}
			catch
			{
			}
		}
	}

	public static bool OpenWorkBook(string ExcelWorkbookName, bool showExcel, out string warnstring)
	{
		warnstring = "";
		string warnstring2 = "";
		Application oExcel = null;
		Workbook theWorkbook = null;
		try
		{
			if (!OpenExcelWithWorkBook(ref oExcel, ExcelWorkbookName, out theWorkbook, showExcel, out warnstring2))
			{
				warnstring = "Error Opening WorkBook - " + warnstring2;
				return false;
			}
		}
		catch (Exception ex)
		{
			warnstring = "Error Opening WorkBook - " + ex.Message;
			return false;
		}
		return true;
	}

	public static bool OpenXmlInExcel(string XMLFileName)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		try
		{
			if (XMLFileName.Length > 0)
			{
				Application val = (Application)Marshal.GetActiveObject("Excel.Application");
				((_Application)val).Visible = true;
				((_Application)val).UserControl = true;
				((_Application)val).Visible = true;
				((_Application)val).UserControl = true;
				Workbooks workbooks = ((_Application)val).Workbooks;
				workbooks.OpenXML(XMLFileName, (object)1, (object)2);
			}
			return true;
		}
		catch
		{
			return false;
		}
	}

	public static bool OpenExcelWithWorkBook(ref Application oExcel, string ExcelWorkbookName, out Workbook theWorkbook, bool showExcel, out string warnstring)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		warnstring = "";
		theWorkbook = null;
		try
		{
			oExcel = (Application)Marshal.GetActiveObject("Excel.Application");
		}
		catch
		{
			oExcel = (Application)new ApplicationClass();
		}
		try
		{
			((_Application)oExcel).UserControl = true;
			((_Application)oExcel).DisplayAlerts = true;
			theWorkbook = null;
			bool flag = false;
			if (((_Application)oExcel).Workbooks.Count > 0)
			{
				Workbooks workbooks = ((_Application)oExcel).Workbooks;
				for (int i = 1; i <= workbooks.Count; i++)
				{
					theWorkbook = workbooks[(object)i];
					if (((_Workbook)theWorkbook).FullName.ToUpper() == ExcelWorkbookName.ToUpper())
					{
						flag = true;
						((_Workbook)theWorkbook).Activate();
						break;
					}
				}
			}
			if (!flag)
			{
				if (File.Exists(ExcelWorkbookName))
				{
					theWorkbook = ((_Application)oExcel).Workbooks.Open(ExcelWorkbookName, (object)0, (object)false, (object)5, (object)"", (object)"", (object)true, (object)(XlPlatform)2, (object)"\t", (object)false, (object)false, (object)0, (object)true, (object)Missing.Value, (object)Missing.Value);
				}
				else
				{
					theWorkbook = ((_Application)oExcel).Workbooks.Add((object)Missing.Value);
					((_Workbook)theWorkbook).SaveAs((object)ExcelWorkbookName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, (XlSaveAsAccessMode)1, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
				}
			}
			((_Application)oExcel).Visible = showExcel;
			return true;
		}
		catch (Exception ex)
		{
			warnstring = "Error opening workbook " + ExcelWorkbookName + ":" + ex.Message;
			return false;
		}
	}

	public static bool ExportWideOrExtendedView(ExcelArgs eArgs, bool closeAfterExport, out string errorMessage)
	{
		//IL_0498: Unknown result type (might be due to invalid IL or missing references)
		//IL_049f: Expected O, but got Unknown
		//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04dc: Expected O, but got Unknown
		//IL_0423: Unknown result type (might be due to invalid IL or missing references)
		//IL_0429: Expected O, but got Unknown
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Expected O, but got Unknown
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Expected O, but got Unknown
		//IL_070c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0712: Expected O, but got Unknown
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: Unknown result type (might be due to invalid IL or missing references)
		//IL_0338: Expected O, but got Unknown
		//IL_0308: Unknown result type (might be due to invalid IL or missing references)
		//IL_030e: Expected O, but got Unknown
		//IL_0594: Unknown result type (might be due to invalid IL or missing references)
		//IL_059a: Expected O, but got Unknown
		//IL_056a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0570: Expected O, but got Unknown
		//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0373: Unknown result type (might be due to invalid IL or missing references)
		//IL_0379: Expected O, but got Unknown
		//IL_060b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0611: Expected O, but got Unknown
		//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e7: Expected O, but got Unknown
		//IL_064c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0652: Expected O, but got Unknown
		errorMessage = "";
		Application objExcel = null;
		Workbook objWorkBook = null;
		Worksheet objWorkSheet = null;
		Range objWorkingRange = null;
		Range objWorkingRange2 = null;
		XmlMap selectedMap = null;
		if (!File.Exists(eArgs.TemplateFileName))
		{
			errorMessage = "Could not locate the template file - " + eArgs.TemplateFileName;
			return false;
		}
		if (!File.Exists(eArgs.SourceXMLFileName))
		{
			errorMessage = "Could not locate the source XML file - " + eArgs.TemplateFileName;
			return false;
		}
		bool newExcelApplication = false;
		OpenExcel(ref objExcel, out newExcelApplication);
		((_Application)objExcel).Visible = eArgs.ShowExcel;
		if (objExcel != null)
		{
		}
		if (IsWorkBookOpen(ref objExcel, ref objWorkBook, eArgs.WorkBookName, out errorMessage))
		{
			((_Workbook)objWorkBook).Activate();
		}
		else
		{
			if (errorMessage.Length > 0)
			{
				CleanUpExcelObjects(selectedMap, objWorkingRange, objWorkingRange2, objWorkSheet, objWorkBook, objExcel, closeAfterExport);
				return false;
			}
			if (File.Exists(eArgs.WorkBookName))
			{
				if (!OpenWorkBook(ref objExcel, ref objWorkBook, eArgs.WorkBookName, out errorMessage))
				{
					CleanUpExcelObjects(selectedMap, objWorkingRange, objWorkingRange2, objWorkSheet, objWorkBook, objExcel, closeAfterExport);
					return false;
				}
			}
			else if (!CreateWorkBook(eArgs.WorkBookName, ref objExcel, ref objWorkBook, out errorMessage))
			{
				CleanUpExcelObjects(selectedMap, objWorkingRange, objWorkingRange2, objWorkSheet, objWorkBook, objExcel, closeAfterExport);
				return false;
			}
		}
		if (!closeAfterExport)
		{
			((_Application)objExcel).Visible = true;
		}
		bool flag = false;
		if (eArgs.WorkSheetName.Length > 0)
		{
			if (SheetExists(eArgs.WorkSheetName, ref objWorkBook, ref objWorkSheet, out errorMessage))
			{
				try
				{
					((_Worksheet)objWorkSheet).Activate();
				}
				catch
				{
				}
			}
			else
			{
				if (errorMessage.Length > 0)
				{
					CleanUpExcelObjects(selectedMap, objWorkingRange, objWorkingRange2, objWorkSheet, objWorkBook, objExcel, closeAfterExport);
					return false;
				}
				if (!AddSheet(eArgs.WorkSheetName, ref objWorkBook, ref objWorkSheet, eArgs.TemplateFileName, out errorMessage))
				{
					string defaultWorkSheetName = GetDefaultWorkSheetName();
					if (defaultWorkSheetName.Length <= 0)
					{
						CleanUpExcelObjects(selectedMap, objWorkingRange, objWorkingRange2, objWorkSheet, objWorkBook, objExcel, closeAfterExport);
						return false;
					}
					if (!AddSheet(defaultWorkSheetName, ref objWorkBook, ref objWorkSheet, eArgs.TemplateFileName, out errorMessage))
					{
						CleanUpExcelObjects(selectedMap, objWorkingRange, objWorkingRange2, objWorkSheet, objWorkBook, objExcel, closeAfterExport);
						return false;
					}
					flag = true;
				}
			}
		}
		else
		{
			string defaultWorkSheetName2 = GetDefaultWorkSheetName();
			if (defaultWorkSheetName2.Length <= 0)
			{
				CleanUpExcelObjects(selectedMap, objWorkingRange, objWorkingRange2, objWorkSheet, objWorkBook, objExcel, closeAfterExport);
				return false;
			}
			if (!AddSheet(defaultWorkSheetName2, ref objWorkBook, ref objWorkSheet, eArgs.TemplateFileName, out errorMessage))
			{
				CleanUpExcelObjects(selectedMap, objWorkingRange, objWorkingRange2, objWorkSheet, objWorkBook, objExcel, closeAfterExport);
				return false;
			}
			flag = true;
		}
		TemplateSheetInfo templateSheetInfo = new TemplateSheetInfo();
		if (!GetTemplateBoundaries(ref objWorkSheet, ref objWorkingRange, ref templateSheetInfo, out errorMessage))
		{
			CleanUpExcelObjects(selectedMap, objWorkingRange, objWorkingRange2, objWorkSheet, objWorkBook, objExcel, closeAfterExport);
			return false;
		}
		if (!SetTemplateForImport(ref objWorkSheet, ref objWorkingRange, ref objWorkingRange2, ref templateSheetInfo, eArgs, flag, out errorMessage))
		{
			CleanUpExcelObjects(selectedMap, objWorkingRange, objWorkingRange2, objWorkSheet, objWorkBook, objExcel, closeAfterExport);
			return false;
		}
		if (!eArgs.AppendToSheet || flag)
		{
			try
			{
				((_Worksheet)objWorkSheet).Activate();
				objWorkingRange = ((templateSheetInfo.DataStartCell.Column <= 1) ? ((Range)((_Worksheet)objWorkSheet).Cells[(object)templateSheetInfo.DataStartCell.Row, (object)2]) : ((Range)((_Worksheet)objWorkSheet).Cells[(object)templateSheetInfo.DataStartCell.Row, (object)1]));
				((_Workbook)objWorkBook).XmlImport(eArgs.SourceXMLFileName, ref selectedMap, (object)false, (object)objWorkingRange);
				objWorkingRange = ((templateSheetInfo.DataStartCell.Column <= 1) ? ((Range)((_Worksheet)objWorkSheet).Cells[(object)templateSheetInfo.DataStartCell.Row, (object)2]) : ((Range)((_Worksheet)objWorkSheet).Cells[(object)templateSheetInfo.DataStartCell.Row, (object)1]));
				objWorkingRange2 = ((_Worksheet)objWorkSheet).UsedRange;
				objWorkingRange.EntireRow.WrapText = true;
				for (int i = 1; i <= objWorkingRange2.Columns.Count; i++)
				{
					objWorkingRange = (Range)((_Worksheet)objWorkSheet).Cells[(object)objWorkingRange.Row, (object)i];
					objWorkingRange.EntireColumn.WrapText = true;
					objWorkingRange.ColumnWidth = 10;
				}
				selectedMap.Name = ((_Worksheet)objWorkSheet).Name;
				((_Workbook)objWorkBook).Save();
			}
			catch (Exception ex)
			{
				errorMessage = "Error importing XML using XMLImport - " + ex.Message;
				CleanUpExcelObjects(selectedMap, objWorkingRange, objWorkingRange2, objWorkSheet, objWorkBook, objExcel, closeAfterExport);
				return false;
			}
			for (int j = templateSheetInfo.DataStartCell.Column; j <= templateSheetInfo.DataEndCell.Column; j++)
			{
				objWorkingRange = (Range)((_Worksheet)objWorkSheet).Cells[(object)templateSheetInfo.DataStartCell.Row, (object)j];
				string text = "";
				try
				{
					text = objWorkingRange.Value2.ToString().Trim();
				}
				catch
				{
				}
				if (text.Length > 0 && eArgs.ParameterInfoDictionary.ContainsKey(text))
				{
					try
					{
						ParameterInfo parameterInfo = eArgs.ParameterInfoDictionary[text];
						objWorkingRange2 = (Range)((_Worksheet)objWorkSheet).Cells[(object)templateSheetInfo.UpperLimitCell.Row, (object)j];
						objWorkingRange2.Value2 = parameterInfo.UpperLimit;
						objWorkingRange2 = (Range)((_Worksheet)objWorkSheet).Cells[(object)templateSheetInfo.LowerLimitCell.Row, (object)j];
						objWorkingRange2.Value2 = parameterInfo.LowerLimit;
					}
					catch
					{
					}
				}
			}
		}
		else
		{
			try
			{
				if (!SelectXmlMap(ref objWorkBook, ((_Worksheet)objWorkSheet).Name, out selectedMap, out errorMessage))
				{
					return false;
				}
				if (selectedMap == null)
				{
					errorMessage = "Could not find the Xml Map for the worksheet " + ((_Worksheet)objWorkSheet).Name;
					CleanUpExcelObjects(selectedMap, objWorkingRange, objWorkingRange2, objWorkSheet, objWorkBook, objExcel, closeAfterExport);
					return false;
				}
				((_Worksheet)objWorkSheet).Activate();
				objWorkingRange = ((templateSheetInfo.DataStartCell.Column <= 1) ? ((Range)((_Worksheet)objWorkSheet).Cells[(object)templateSheetInfo.DataStartCell.Row, (object)2]) : ((Range)((_Worksheet)objWorkSheet).Cells[(object)templateSheetInfo.DataStartCell.Row, (object)1]));
				((_Workbook)objWorkBook).XmlImport(eArgs.SourceXMLFileName, ref selectedMap, (object)false, (object)objWorkingRange);
				objWorkingRange = ((templateSheetInfo.DataStartCell.Column <= 1) ? ((Range)((_Worksheet)objWorkSheet).Cells[(object)templateSheetInfo.DataStartCell.Row, (object)2]) : ((Range)((_Worksheet)objWorkSheet).Cells[(object)templateSheetInfo.DataStartCell.Row, (object)1]));
				objWorkingRange2 = ((_Worksheet)objWorkSheet).UsedRange;
				objWorkingRange.EntireRow.WrapText = true;
				for (int k = 1; k <= objWorkingRange2.Columns.Count; k++)
				{
					objWorkingRange = (Range)((_Worksheet)objWorkSheet).Cells[(object)objWorkingRange.Row, (object)k];
					objWorkingRange.EntireColumn.WrapText = true;
					objWorkingRange.ColumnWidth = 10;
				}
				((_Workbook)objWorkBook).Save();
			}
			catch (Exception ex2)
			{
				errorMessage = "Error importing XML using XMLImport - " + ex2.Message;
				CleanUpExcelObjects(selectedMap, objWorkingRange, objWorkingRange2, objWorkSheet, objWorkBook, objExcel, closeAfterExport);
				return false;
			}
		}
		if (eArgs.FirstRowIsDummy)
		{
			objWorkingRange = (Range)((_Worksheet)objWorkSheet).Cells[(object)(templateSheetInfo.DataStartCell.Row + 1), (object)1];
			objWorkingRange.EntireRow.Delete((object)true);
		}
		try
		{
			((_Workbook)objWorkBook).Save();
		}
		catch
		{
		}
		if (!closeAfterExport)
		{
			((_Application)objExcel).Visible = true;
		}
		CleanUpExcelObjects(selectedMap, objWorkingRange, objWorkingRange2, objWorkSheet, objWorkBook, objExcel, closeAfterExport);
		return true;
	}

	public static void ExportToExcel(DataTable dt, ExcelArgs eArgs)
	{
		if (dt == null)
		{
			throw new ArgumentNullException("dt", "Error exporting to excel. Data is invalid");
		}
		try
		{
			ExcelManager.OpenExcel(showexcel: false);
			OpenWorkbookArguments openWorkbookArguments = new OpenWorkbookArguments();
			openWorkbookArguments.Filename = eArgs.WorkBookName;
			openWorkbookArguments.CreateNew = true;
			ExcelManager.OpenWorkBook(openWorkbookArguments);
			AddSheetArguments addSheetArguments = new AddSheetArguments();
			addSheetArguments.BeforeAsString = "Sheet1";
			if (string.IsNullOrEmpty(eArgs.WorkSheetName))
			{
				addSheetArguments.SheetName = GetDefaultWorkSheetName();
			}
			else
			{
				addSheetArguments.SheetName = eArgs.WorkSheetName;
			}
			ExcelManager.AddSheet(addSheetArguments);
			ExcelManager.SelectWorkSheet(addSheetArguments.SheetName);
			FormatExcelSheetColumns(dt);
			ExcelCell startCell = new ExcelCell(1, 1);
			ExcelManager.InsertDataTableUsingArray(dt, startCell);
			FormatExcelData();
			ExcelManager.SaveCurrentWorkBook();
			ExcelManager.SetExcelVisibility(eArgs.ShowExcel);
		}
		finally
		{
			try
			{
				ExcelManager.ReleaseExcel();
			}
			catch
			{
			}
		}
	}

	private static void FormatExcelSheetColumns(DataTable dt)
	{
		for (int i = 0; i < dt.Columns.Count; i++)
		{
			int columnIndex = i + 1;
			if (dt.Columns[i].DataType == typeof(string))
			{
				ExcelManager.SetColumnFormatting(columnIndex, "@");
			}
			else if (dt.Columns[i].DataType == typeof(DateTime))
			{
				ExcelManager.SetColumnFormatting(columnIndex, "[$-409]m/d/yy h:mm AM/PM;@");
			}
			else if (dt.Columns[i].DataType == typeof(int))
			{
				ExcelManager.SetColumnFormatting(columnIndex, "0");
			}
			else if (dt.Columns[i].DataType == typeof(long))
			{
				ExcelManager.SetColumnFormatting(columnIndex, "0");
			}
			else if (dt.Columns[i].DataType == typeof(float))
			{
				ExcelManager.SetColumnFormatting(columnIndex, "0.00000");
			}
			else if (dt.Columns[i].DataType == typeof(double))
			{
				ExcelManager.SetColumnFormatting(columnIndex, "0.00000");
			}
			else
			{
				ExcelManager.SetColumnFormatting(columnIndex, "@");
			}
		}
	}

	private static void FormatExcelData()
	{
		ExcelRange usedRange = ExcelManager.GetUsedRange();
		ExcelManager.SetAutoFilter(usedRange);
		ExcelManager.ColumnAutoFit(usedRange);
		ExcelRange excelRange = new ExcelRange();
		excelRange.StartCell = usedRange.StartCell.Copy();
		excelRange.EndCell = new ExcelCell(excelRange.StartCell.RowIndex, usedRange.EndCell.ColumnIndex);
		ExcelManager.SetRangeFontBold(excelRange, enableBold: true);
	}

	public static void ExportLongWideView(DataTable longWideViewTbl, ExcelArgs eArgs, int unitsColumnStartIndex, int unitsColumnEndIndex)
	{
		if (longWideViewTbl == null)
		{
			throw new ArgumentNullException("LongWideViewTbl", "Error exporting Long Wide view data to excel. Long Wide view data is Invalid");
		}
		try
		{
			ExcelManager.OpenExcel(showexcel: false);
			OpenWorkbookArguments openWorkbookArguments = new OpenWorkbookArguments();
			openWorkbookArguments.Filename = eArgs.WorkBookName;
			openWorkbookArguments.CreateNew = true;
			ExcelManager.OpenWorkBook(openWorkbookArguments);
			WriteLongWideViewToExcelSheet(longWideViewTbl, eArgs.WorkSheetName, unitsColumnStartIndex, unitsColumnEndIndex, writeStatistics: true);
			ExcelManager.SaveCurrentWorkBook();
			ExcelManager.SetExcelVisibility(eArgs.ShowExcel);
		}
		finally
		{
			try
			{
				ExcelManager.ReleaseExcel();
			}
			catch
			{
			}
		}
	}

	public static void WriteLongWideViewToExcelSheet(DataTable longWideViewTbl, string excelSheetName, int unitsColumnStartIndex, int unitsColumnEndIndex, bool writeStatistics)
	{
		if (string.IsNullOrEmpty(excelSheetName))
		{
			throw new ArgumentException("Excel sheet name cannot be empty");
		}
		if (longWideViewTbl == null)
		{
			throw new ArgumentNullException("LongWideViewData", "Long Wide view data is Invalid. Export to excel cannot be completed");
		}
		AddSheetArguments addSheetArguments = new AddSheetArguments();
		addSheetArguments.SheetName = excelSheetName;
		addSheetArguments.BeforeAsString = "Sheet1";
		ExcelManager.AddSheet(addSheetArguments);
		ExcelManager.SelectWorkSheet(addSheetArguments.SheetName);
		ExcelCell startCell = new ExcelCell(1, 1);
		int num = longWideViewTbl.Columns.IndexOf("DataIdentifier");
		int num2 = longWideViewTbl.Columns.IndexOf("UpperLimit");
		int num3 = longWideViewTbl.Columns.IndexOf("LowerLimit");
		int num4 = unitsColumnStartIndex + 1;
		int num5 = unitsColumnEndIndex + 1;
		FormatExcelSheetColumns(longWideViewTbl);
		ExcelManager.InsertDataTableUsingArray(longWideViewTbl, startCell);
		ExcelRange usedRange = ExcelManager.GetUsedRange();
		if (writeStatistics)
		{
			ExcelCell excelCell = new ExcelCell(usedRange.StartCell.RowIndex, usedRange.EndCell.ColumnIndex + 1);
			ExcelManager.SetCellValue(excelCell, "Min");
			ExcelRange excelRange = new ExcelRange();
			excelRange.StartCell = new ExcelCell(excelCell.RowIndex + 1, excelCell.ColumnIndex);
			excelRange.EndCell = new ExcelCell(usedRange.EndCell.RowIndex, excelCell.ColumnIndex);
			int num6 = usedRange.StartCell.RowIndex + 1 - excelRange.StartCell.RowIndex;
			int num7 = num4 - excelRange.StartCell.ColumnIndex;
			int num8 = num5 - excelRange.EndCell.ColumnIndex;
			ExcelManager.SetRangeNumberFormat(excelRange, "0.00000");
			ExcelManager.SetFormula(excelRange, string.Format("=MIN('{0}'!R[{1}]C[{2}]:R[{1}]C[{3}])", excelSheetName, num6, num7, num8));
			ExcelCell excelCell2 = new ExcelCell(usedRange.StartCell.RowIndex, usedRange.EndCell.ColumnIndex + 2);
			ExcelManager.SetCellValue(excelCell2, "Max");
			ExcelRange excelRange2 = new ExcelRange();
			excelRange2.StartCell = new ExcelCell(excelCell2.RowIndex + 1, excelCell2.ColumnIndex);
			excelRange2.EndCell = new ExcelCell(usedRange.EndCell.RowIndex, excelCell2.ColumnIndex);
			int num9 = usedRange.StartCell.RowIndex + 1 - excelRange2.StartCell.RowIndex;
			int num10 = num4 - excelRange2.StartCell.ColumnIndex;
			int num11 = num5 - excelRange2.EndCell.ColumnIndex;
			ExcelManager.SetRangeNumberFormat(excelRange2, "0.00000");
			ExcelManager.SetFormula(excelRange2, string.Format("=MAX('{0}'!R[{1}]C[{2}]:R[{1}]C[{3}])", excelSheetName, num9, num10, num11));
			ExcelCell excelCell3 = new ExcelCell(usedRange.StartCell.RowIndex, usedRange.EndCell.ColumnIndex + 3);
			ExcelManager.SetCellValue(excelCell3, "Mean");
			ExcelRange excelRange3 = new ExcelRange();
			excelRange3.StartCell = new ExcelCell(excelCell3.RowIndex + 1, excelCell3.ColumnIndex);
			excelRange3.EndCell = new ExcelCell(usedRange.EndCell.RowIndex, excelCell3.ColumnIndex);
			int num12 = usedRange.StartCell.RowIndex + 1 - excelRange3.StartCell.RowIndex;
			int num13 = num4 - excelRange3.StartCell.ColumnIndex;
			int num14 = num5 - excelRange3.EndCell.ColumnIndex;
			ExcelManager.SetRangeNumberFormat(excelRange3, "0.00000");
			ExcelManager.SetFormula(excelRange3, string.Format("=AVERAGE('{0}'!R[{1}]C[{2}]:R[{1}]C[{3}])", excelSheetName, num12, num13, num14));
			ExcelCell excelCell4 = new ExcelCell(usedRange.StartCell.RowIndex, usedRange.EndCell.ColumnIndex + 4);
			ExcelManager.SetCellValue(excelCell4, "STD. Dev");
			ExcelRange excelRange4 = new ExcelRange();
			excelRange4.StartCell = new ExcelCell(excelCell4.RowIndex + 1, excelCell4.ColumnIndex);
			excelRange4.EndCell = new ExcelCell(usedRange.EndCell.RowIndex, excelCell4.ColumnIndex);
			int num15 = usedRange.StartCell.RowIndex + 1 - excelRange4.StartCell.RowIndex;
			int num16 = num4 - excelRange4.StartCell.ColumnIndex;
			int num17 = num5 - excelRange4.EndCell.ColumnIndex;
			ExcelManager.SetRangeNumberFormat(excelRange4, "0.00000");
			ExcelManager.SetFormula(excelRange4, string.Format("=STDEV('{0}'!R[{1}]C[{2}]:R[{1}]C[{3}])", excelSheetName, num15, num16, num17));
			ExcelCell excelCell5 = new ExcelCell(usedRange.StartCell.RowIndex, usedRange.EndCell.ColumnIndex + 5);
			ExcelManager.SetCellValue(excelCell5, "Q1");
			ExcelRange excelRange5 = new ExcelRange();
			excelRange5.StartCell = new ExcelCell(excelCell5.RowIndex + 1, excelCell5.ColumnIndex);
			excelRange5.EndCell = new ExcelCell(usedRange.EndCell.RowIndex, excelCell5.ColumnIndex);
			int num18 = usedRange.StartCell.RowIndex + 1 - excelRange5.StartCell.RowIndex;
			int num19 = num4 - excelRange5.StartCell.ColumnIndex;
			int num20 = num5 - excelRange5.EndCell.ColumnIndex;
			ExcelManager.SetRangeNumberFormat(excelRange5, "0.00000");
			ExcelManager.SetFormula(excelRange5, string.Format("=QUARTILE('{0}'!R[{1}]C[{2}]:R[{1}]C[{3}], 1)", excelSheetName, num18, num19, num20));
			ExcelCell excelCell6 = new ExcelCell(usedRange.StartCell.RowIndex, usedRange.EndCell.ColumnIndex + 6);
			ExcelManager.SetCellValue(excelCell6, "Q3");
			ExcelRange excelRange6 = new ExcelRange();
			excelRange6.StartCell = new ExcelCell(excelCell6.RowIndex + 1, excelCell6.ColumnIndex);
			excelRange6.EndCell = new ExcelCell(usedRange.EndCell.RowIndex, excelCell6.ColumnIndex);
			int num21 = usedRange.StartCell.RowIndex + 1 - excelRange6.StartCell.RowIndex;
			int num22 = num4 - excelRange6.StartCell.ColumnIndex;
			int num23 = num5 - excelRange6.EndCell.ColumnIndex;
			ExcelManager.SetRangeNumberFormat(excelRange6, "0.00000");
			ExcelManager.SetFormula(excelRange6, string.Format("=QUARTILE('{0}'!R[{1}]C[{2}]:R[{1}]C[{3}], 3)", excelSheetName, num21, num22, num23));
			ExcelCell excelCell7 = new ExcelCell(usedRange.StartCell.RowIndex, usedRange.EndCell.ColumnIndex + 7);
			ExcelManager.SetCellValue(excelCell7, "Median");
			ExcelRange excelRange7 = new ExcelRange();
			excelRange7.StartCell = new ExcelCell(excelCell7.RowIndex + 1, excelCell7.ColumnIndex);
			excelRange7.EndCell = new ExcelCell(usedRange.EndCell.RowIndex, excelCell7.ColumnIndex);
			int num24 = usedRange.StartCell.RowIndex + 1 - excelRange7.StartCell.RowIndex;
			int num25 = num4 - excelRange7.StartCell.ColumnIndex;
			int num26 = num5 - excelRange7.EndCell.ColumnIndex;
			ExcelManager.SetRangeNumberFormat(excelRange7, "0.00000");
			ExcelManager.SetFormula(excelRange7, string.Format("=MEDIAN('{0}'!R[{1}]C[{2}]:R[{1}]C[{3}])", excelSheetName, num24, num25, num26));
			ExcelCell excelCell8 = new ExcelCell(usedRange.StartCell.RowIndex, usedRange.EndCell.ColumnIndex + 7);
			ExcelManager.SetCellValue(excelCell8, "Number of Units");
			ExcelRange excelRange8 = new ExcelRange();
			excelRange8.StartCell = new ExcelCell(excelCell8.RowIndex + 1, excelCell8.ColumnIndex);
			excelRange8.EndCell = new ExcelCell(usedRange.EndCell.RowIndex, excelCell8.ColumnIndex);
			int num27 = usedRange.StartCell.RowIndex + 1 - excelRange8.StartCell.RowIndex;
			int num28 = num4 - excelRange8.StartCell.ColumnIndex;
			int num29 = num5 - excelRange8.EndCell.ColumnIndex;
			ExcelManager.SetRangeNumberFormat(excelRange8, "0.00000");
			ExcelManager.SetFormula(excelRange8, string.Format("=SUBTOTAL(102,'{0}'!R[{1}]C[{2}]:R[{1}]C[{3}])", excelSheetName, num27, num28, num29));
			ExcelCell excelCell9 = new ExcelCell(usedRange.StartCell.RowIndex, usedRange.EndCell.ColumnIndex + 8);
			ExcelManager.SetCellValue(excelCell9, "Mean LSL");
			ExcelRange excelRange9 = new ExcelRange();
			excelRange9.StartCell = new ExcelCell(excelCell9.RowIndex + 1, excelCell9.ColumnIndex);
			excelRange9.EndCell = new ExcelCell(usedRange.EndCell.RowIndex, excelCell9.ColumnIndex);
			int num30 = usedRange.StartCell.RowIndex + 1 - excelRange9.StartCell.RowIndex;
			int num31 = excelCell3.ColumnIndex - excelRange9.StartCell.ColumnIndex;
			int num32 = usedRange.StartCell.ColumnIndex + num3 - excelRange9.EndCell.ColumnIndex;
			ExcelManager.SetRangeNumberFormat(excelRange9, "0.00000");
			ExcelManager.SetFormula(excelRange9, string.Format("='{0}'!R[{1}]C[{2}] - '{0}'!R[{1}]C[{3}]", excelSheetName, num30, num31, num32));
			ExcelCell excelCell10 = new ExcelCell(usedRange.StartCell.RowIndex, usedRange.EndCell.ColumnIndex + 9);
			ExcelManager.SetCellValue(excelCell10, "UL Mean");
			ExcelRange excelRange10 = new ExcelRange();
			excelRange10.StartCell = new ExcelCell(excelCell10.RowIndex + 1, excelCell10.ColumnIndex);
			excelRange10.EndCell = new ExcelCell(usedRange.EndCell.RowIndex, excelCell10.ColumnIndex);
			int num33 = usedRange.StartCell.RowIndex + 1 - excelRange10.StartCell.RowIndex;
			int num34 = excelCell3.ColumnIndex - excelRange10.StartCell.ColumnIndex;
			int num35 = usedRange.StartCell.ColumnIndex + num2 - excelRange10.EndCell.ColumnIndex;
			ExcelManager.SetRangeNumberFormat(excelRange10, "0.00000");
			ExcelManager.SetFormula(excelRange10, string.Format("='{0}'!R[{1}]C[{2}] - '{0}'!R[{1}]C[{3}]", excelSheetName, num33, num35, num34));
			ExcelCell excelCell11 = new ExcelCell(usedRange.StartCell.RowIndex, usedRange.EndCell.ColumnIndex + 10);
			ExcelManager.SetCellValue(excelCell11, "CPK");
			ExcelRange excelRange11 = new ExcelRange();
			excelRange11.StartCell = new ExcelCell(excelCell11.RowIndex + 1, excelCell11.ColumnIndex);
			excelRange11.EndCell = new ExcelCell(usedRange.EndCell.RowIndex, excelCell11.ColumnIndex);
			int num36 = usedRange.StartCell.RowIndex + 1 - excelRange11.StartCell.RowIndex;
			int num37 = excelCell9.ColumnIndex - excelRange11.StartCell.ColumnIndex;
			int num38 = excelCell10.ColumnIndex - excelRange11.StartCell.ColumnIndex;
			int num39 = excelCell4.ColumnIndex - excelRange11.StartCell.ColumnIndex;
			ExcelManager.SetRangeNumberFormat(excelRange11, "0.00000");
			ExcelManager.SetFormula(excelRange11, string.Format("=MIN('{0}'!R[{1}]C[{2}], '{0}'!R[{1}]C[{3}])/(3 *'{0}'!R[{1}]C[{4}])", excelSheetName, num36, num37, num38, num39));
		}
		usedRange = ExcelManager.GetUsedRange();
		ExcelManager.SetAutoFilter(usedRange);
		ExcelManager.ColumnAutoFit(usedRange);
		ExcelRange excelRange12 = new ExcelRange();
		excelRange12.StartCell = usedRange.StartCell.Copy();
		excelRange12.EndCell = new ExcelCell(excelRange12.StartCell.RowIndex, usedRange.EndCell.ColumnIndex);
		ExcelManager.SetRangeFontBold(excelRange12, enableBold: true);
		ExcelManager.CutColumnContents(num + 1, usedRange.EndCell.ColumnIndex + 1);
		ExcelManager.DeleteEntireColumn(num + 1, shiftColumns: true);
	}

	private static void CleanUpExcelObjects(XmlMap xMap, Range objRange1, Range objRange2, Worksheet objWorkSheet, Workbook objWorkBook, Application objExcel, bool closeAfterExport)
	{
		try
		{
			try
			{
				if (xMap != null)
				{
					Marshal.ReleaseComObject(xMap);
				}
				if (objRange1 != null)
				{
					Marshal.ReleaseComObject(objRange1);
				}
				if (objRange2 != null)
				{
					Marshal.ReleaseComObject(objRange2);
				}
				if (objWorkSheet != null)
				{
					Marshal.ReleaseComObject(objWorkSheet);
				}
				if (objWorkBook != null)
				{
					Marshal.ReleaseComObject(objWorkBook);
				}
				if (objExcel != null)
				{
					Marshal.ReleaseComObject(objExcel);
				}
				GC.Collect();
			}
			catch
			{
			}
			if (closeAfterExport)
			{
				CloseExcel(forceclose: true);
			}
		}
		catch
		{
		}
	}

	public static void OpenExcel(ref Application objExcel, out bool newExcelApplication)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Expected O, but got Unknown
		newExcelApplication = false;
		try
		{
			objExcel = (Application)Marshal.GetActiveObject("Excel.Application");
			newExcelApplication = false;
		}
		catch
		{
			objExcel = (Application)new ApplicationClass();
			newExcelApplication = true;
		}
	}

	public static bool IsWorkBookOpen(ref Application objExcel, ref Workbook objWorkBook, string workBookName, out string errorMessage)
	{
		errorMessage = "";
		try
		{
			if (objExcel != null)
			{
				if (((_Application)objExcel).Workbooks != null)
				{
					for (int i = 1; i <= ((_Application)objExcel).Workbooks.Count; i++)
					{
						Workbook val = ((_Application)objExcel).Workbooks[(object)i];
						if (((_Workbook)val).FullName.ToLower() == workBookName.ToLower())
						{
							objWorkBook = ((_Application)objExcel).Workbooks[(object)i];
							return true;
						}
						if (val != null)
						{
							Marshal.ReleaseComObject(val);
						}
					}
					return false;
				}
				return false;
			}
			errorMessage = "Excel application not initialized";
			return false;
		}
		catch (Exception ex)
		{
			errorMessage = "Error checking if workbook is open - " + ex.Message;
			return false;
		}
	}

	public static bool OpenWorkBook(ref Application objExcel, ref Workbook objWorkBook, string workBookName, out string errorMessage)
	{
		errorMessage = "";
		if (File.Exists(workBookName))
		{
			if (objExcel != null && ((_Application)objExcel).Workbooks != null)
			{
				try
				{
					objWorkBook = ((_Application)objExcel).Workbooks.Open(workBookName, (object)0, (object)false, (object)5, (object)"", (object)"", (object)true, (object)(XlPlatform)2, (object)"\t", (object)false, (object)false, (object)0, (object)true, (object)Missing.Value, (object)Missing.Value);
					return true;
				}
				catch (Exception ex)
				{
					errorMessage = "Error opening workbook " + workBookName + " - " + ex.Message;
					return false;
				}
			}
			errorMessage = "Excel not initialized";
			return false;
		}
		errorMessage = "Workbook does not exist";
		return false;
	}

	public static bool CreateWorkBook(string workBookName, ref Application objExcel, ref Workbook objWorkBook, out string errorMessage)
	{
		errorMessage = "";
		if (objExcel != null)
		{
			try
			{
				objWorkBook = ((_Application)objExcel).Workbooks.Add((object)Missing.Value);
				((_Workbook)objWorkBook).SaveAs((object)workBookName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, (XlSaveAsAccessMode)1, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
			}
			catch (Exception ex)
			{
				errorMessage = "Error creating workbook " + workBookName + " - " + ex.Message;
				return false;
			}
			return true;
		}
		errorMessage = "Excel not initialized";
		return false;
	}

	public static bool SheetExists(string sheetName, ref Workbook objWorkBook, ref Worksheet objWorkSheet, out string errorMessage)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Expected O, but got Unknown
		errorMessage = "";
		try
		{
			if (objWorkBook != null)
			{
				if (((_Workbook)objWorkBook).Sheets != null)
				{
					if (((_Workbook)objWorkBook).Sheets.Count > 0)
					{
						for (int i = 1; i <= ((_Workbook)objWorkBook).Sheets.Count; i++)
						{
							Worksheet val = (Worksheet)((_Workbook)objWorkBook).Sheets[(object)i];
							if (((_Worksheet)val).Name.ToLower() == sheetName.ToLower())
							{
								objWorkSheet = (Worksheet)((_Workbook)objWorkBook).Sheets[(object)i];
								return true;
							}
							if (val != null)
							{
								Marshal.ReleaseComObject(val);
							}
						}
						return false;
					}
					return false;
				}
				return false;
			}
			errorMessage = "Workbook not initialized";
			return false;
		}
		catch (Exception ex)
		{
			errorMessage = "Error checking if worksheet exists " + ex.Message;
			return false;
		}
	}

	public static bool AddSheet(string sheetName, ref Workbook objWorkBook, ref Worksheet objWorkSheet, string templateFileName, out string errorMessage)
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		errorMessage = "";
		if (objWorkBook != null)
		{
			try
			{
				if (templateFileName.Length > 0 && File.Exists(templateFileName))
				{
					objWorkSheet = (Worksheet)((_Workbook)objWorkBook).Sheets.Add(Type.Missing, Type.Missing, Type.Missing, (object)templateFileName);
				}
				else
				{
					objWorkSheet = (Worksheet)((_Workbook)objWorkBook).Sheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
				}
				((_Worksheet)objWorkSheet).Name = sheetName;
				return true;
			}
			catch (Exception ex)
			{
				errorMessage = "Error adding sheet " + sheetName + " - " + ex.Message;
				return false;
			}
		}
		errorMessage = "WorkBook not initialized";
		return false;
	}

	public static string GetDefaultWorkSheetName()
	{
		string text = "";
		text = DateTime.Now.ToString();
		text = text.Replace("/", "");
		text = text.Replace(":", "");
		text = text.Replace(" ", "");
		return "Data_" + text;
	}

	public static bool SelectXmlMap(ref Workbook objWorkBook, string xmlMapName, out XmlMap selectedMap, out string errorMessage)
	{
		errorMessage = "";
		selectedMap = null;
		if (objWorkBook != null)
		{
			try
			{
				if (((_Workbook)objWorkBook).XmlMaps != null && ((_Workbook)objWorkBook).XmlMaps.Count > 0)
				{
					for (int i = 1; i <= ((_Workbook)objWorkBook).XmlMaps.Count; i++)
					{
						XmlMap val = ((_Workbook)objWorkBook).XmlMaps[(object)i];
						if (val.Name == xmlMapName)
						{
							selectedMap = val;
							i = ((_Workbook)objWorkBook).XmlMaps.Count + 1;
						}
						if (val != null)
						{
							Marshal.ReleaseComObject(val);
						}
					}
				}
				return true;
			}
			catch (Exception ex)
			{
				errorMessage = "Error retrieving the xmlmap " + xmlMapName + " - " + ex.Message;
				return false;
			}
		}
		return true;
	}

	public static bool GetTemplateBoundaries(ref Worksheet objWorkSheet, ref Range objWorkingRange1, ref TemplateSheetInfo templateSheetInfo, out string errorMessage)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Expected O, but got Unknown
		errorMessage = "";
		if (objWorkSheet != null)
		{
			try
			{
				objWorkingRange1 = (Range)((_Worksheet)objWorkSheet).Cells[(object)1, (object)1];
				for (int i = 1; i <= 1048576; i++)
				{
					for (int j = 1; j <= 16384; j++)
					{
						objWorkingRange1 = (Range)((_Worksheet)objWorkSheet).Cells[(object)i, (object)j];
						if (objWorkingRange1.Value2 != null)
						{
							try
							{
								objWorkingRange1.Value2.ToString();
								templateSheetInfo.TemplateStartCell.Row = i;
								templateSheetInfo.TemplateStartCell.Column = j;
								i = 1048577;
								j = 16385;
							}
							catch
							{
							}
						}
					}
				}
				if (!templateSheetInfo.TemplateStartCell.IsValid)
				{
					errorMessage = "Error retrieving the starting position of the template";
					return false;
				}
				objWorkingRange1 = (Range)((_Worksheet)objWorkSheet).Cells[(object)1048576, (object)templateSheetInfo.TemplateStartCell.Column];
				objWorkingRange1 = objWorkingRange1[(XlDirection)(-4162)];
				templateSheetInfo.TemplateEndCell.Row = objWorkingRange1.Row;
				templateSheetInfo.TemplateEndCell.Column = templateSheetInfo.TemplateStartCell.Column;
				if (!templateSheetInfo.TemplateEndCell.IsValid)
				{
					errorMessage = "Error retrieving the ending position of the template";
					return false;
				}
				return true;
			}
			catch (Exception ex)
			{
				errorMessage = "Error Retrieving template boundaries - " + ex.Message;
				return false;
			}
		}
		errorMessage = "Error Retrieving template boundaries - Worksheet not initialized";
		return false;
	}

	public static bool SetTemplateForImport(ref Worksheet objWorkSheet, ref Range objWorkingRange1, ref Range objWorkingRange2, ref TemplateSheetInfo templateSheetInfo, ExcelArgs eArgs, bool newSheet, out string errorMessage)
	{
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Expected O, but got Unknown
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Expected O, but got Unknown
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Expected O, but got Unknown
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Expected O, but got Unknown
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Expected O, but got Unknown
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cd: Expected O, but got Unknown
		//IL_05a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ab: Expected O, but got Unknown
		//IL_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_0349: Expected O, but got Unknown
		//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c9: Expected O, but got Unknown
		errorMessage = "";
		if (objWorkSheet != null)
		{
			if (eArgs.AppendToSheet && !newSheet)
			{
				objWorkingRange1 = (Range)((_Worksheet)objWorkSheet).Cells[(object)1048576, (object)2];
				objWorkingRange1 = objWorkingRange1[(XlDirection)(-4162)];
				templateSheetInfo.DataStartCell.Row = objWorkingRange1.Row;
				objWorkingRange1 = (Range)((_Worksheet)objWorkSheet).Cells[(object)(objWorkingRange1.Row - 1), (object)1];
				if (objWorkingRange1.Value2 == null)
				{
					objWorkingRange1 = objWorkingRange1[(XlDirection)(-4161)];
				}
				objWorkingRange2 = (Range)((_Worksheet)objWorkSheet).Cells[(object)objWorkingRange1.Row, (object)(objWorkingRange1.Column + eArgs.ParameterColumnStartIndex - 1)];
				templateSheetInfo.DataStartCell.Column = objWorkingRange2.Column;
			}
			else
			{
				try
				{
					objWorkingRange2 = (Range)((_Worksheet)objWorkSheet).Cells[(object)(templateSheetInfo.TemplateEndCell.Row + 1), (object)templateSheetInfo.TemplateEndCell.Column];
					objWorkingRange1 = (Range)((_Worksheet)objWorkSheet).Cells[(object)(templateSheetInfo.TemplateEndCell.Row + 1), (object)templateSheetInfo.TemplateEndCell.Column];
					objWorkingRange2.Copy(Type.Missing);
					objWorkingRange1.PasteSpecial((XlPasteType)(-4104), (XlPasteSpecialOperation)(-4142), (object)false, (object)false);
					objWorkingRange1.Value2 = "Lower Limit";
					templateSheetInfo.LowerLimitCell.Row = objWorkingRange1.Row;
					templateSheetInfo.LowerLimitCell.Column = objWorkingRange1.Column;
					objWorkingRange1 = (Range)((_Worksheet)objWorkSheet).Cells[(object)(templateSheetInfo.TemplateEndCell.Row + 2), (object)templateSheetInfo.TemplateEndCell.Column];
					objWorkingRange2.Copy(Type.Missing);
					objWorkingRange1.PasteSpecial((XlPasteType)(-4104), (XlPasteSpecialOperation)(-4142), (object)false, (object)false);
					objWorkingRange1.Value2 = "Upper Limit";
					templateSheetInfo.UpperLimitCell.Row = objWorkingRange1.Row;
					templateSheetInfo.UpperLimitCell.Column = objWorkingRange1.Column;
					templateSheetInfo.DataStartCell.Row = templateSheetInfo.UpperLimitCell.Row + 2;
				}
				catch (Exception ex)
				{
					errorMessage = "Error setting the limit cells - " + ex.Message;
					return false;
				}
				if (eArgs.ParameterColumnStartIndex > -1)
				{
					if (eArgs.ParameterColumnStartIndex > 1)
					{
						structRangeProperty structRangeProperty = default(structRangeProperty);
						try
						{
							objWorkingRange1 = (Range)((_Worksheet)objWorkSheet).Cells[(object)1, (object)16384];
							structRangeProperty.ColumnWidth = objWorkingRange1.ColumnWidth;
							structRangeProperty.HorizontalAlignment = objWorkingRange1.HorizontalAlignment;
							structRangeProperty.VerticalAlignment = objWorkingRange1.VerticalAlignment;
							structRangeProperty.WrapText = objWorkingRange1.WrapText;
						}
						catch (Exception ex2)
						{
							errorMessage = "Error saving default column settings before copying extra columns - " + ex2.Message;
							return false;
						}
						for (int i = 2; i <= eArgs.ParameterColumnStartIndex; i++)
						{
							try
							{
								objWorkingRange1 = (Range)((_Worksheet)objWorkSheet).Cells[(object)1, (object)i];
								objWorkingRange1.EntireColumn.Insert((object)(XlDirection)(-4161), Type.Missing);
							}
							catch (Exception ex3)
							{
								errorMessage = "Error inserting the extra column at " + i + " - " + ex3.Message;
								return false;
							}
							try
							{
								objWorkingRange2 = (Range)((_Worksheet)objWorkSheet).Cells[(object)1, (object)i];
								objWorkingRange2.ColumnWidth = structRangeProperty.ColumnWidth;
								objWorkingRange2.HorizontalAlignment = structRangeProperty.HorizontalAlignment;
								objWorkingRange2.VerticalAlignment = structRangeProperty.VerticalAlignment;
								objWorkingRange2.WrapText = structRangeProperty.WrapText;
							}
							catch (Exception ex4)
							{
								errorMessage = "Error setting the column settings of extra columns to default - " + ex4.Message;
								return false;
							}
						}
						templateSheetInfo.DataStartCell.Column = eArgs.ParameterColumnStartIndex + 1;
					}
					else
					{
						templateSheetInfo.DataStartCell.Column = 2;
					}
				}
				else
				{
					templateSheetInfo.DataStartCell.Column = 1;
				}
				int num = eArgs.ParameterColumnEndIndex - eArgs.ParameterColumnStartIndex;
				templateSheetInfo.DataEndCell.Column = templateSheetInfo.DataStartCell.Column + num;
				try
				{
					objWorkingRange1 = ((_Worksheet)objWorkSheet)[((_Worksheet)objWorkSheet).Cells[(object)templateSheetInfo.TemplateStartCell.Row, (object)templateSheetInfo.DataStartCell.Column], ((_Worksheet)objWorkSheet).Cells[(object)(templateSheetInfo.TemplateEndCell.Row + 2), (object)templateSheetInfo.DataStartCell.Column]];
					objWorkingRange1.Select();
					objWorkingRange2 = ((_Worksheet)objWorkSheet)[((_Worksheet)objWorkSheet).Cells[(object)templateSheetInfo.TemplateStartCell.Row, (object)templateSheetInfo.DataStartCell.Column], ((_Worksheet)objWorkSheet).Cells[(object)(templateSheetInfo.TemplateEndCell.Row + 2), (object)templateSheetInfo.DataEndCell.Column]];
					if (templateSheetInfo.DataEndCell.Column > templateSheetInfo.DataStartCell.Column)
					{
						objWorkingRange1.AutoFill(objWorkingRange2, (XlAutoFillType)0);
					}
					objWorkingRange1 = (Range)((_Worksheet)objWorkSheet).Cells[(object)1, (object)1];
				}
				catch (Exception ex5)
				{
					errorMessage = "Error copying the formulas - " + ex5.Message;
					return false;
				}
			}
			return true;
		}
		errorMessage = "Error Setting up the work sheet for import - Worksheet not initialized";
		return false;
	}

	public static bool ImportXmlinExcelWithStats(string MapName, string WorkBookName, string XmlFileName, double[,] LimitsArray, string TemplateFileName, int DataStartCol, bool IncludeCharts, bool DoHiglight, bool showExcel, out string warnstring)
	{
		warnstring = "";
		if (ImportXmlinExcelWithStats(MapName, WorkBookName, XmlFileName, LimitsArray, TemplateFileName, DataStartCol, IncludeCharts, DoHiglight, null, showExcel, out warnstring))
		{
			return true;
		}
		return false;
	}

	public static bool ImportXmlinExcelWithStats(string MapName, string WorkBookName, string XmlFileName, double[,] LimitsArray, string TemplateFileName, int DataStartCol, bool IncludeCharts, bool DoHiglight, string[] UnitLabels, bool showExcel, out string warnstring)
	{
		//IL_03db: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e2: Expected O, but got Unknown
		//IL_046f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0476: Expected O, but got Unknown
		//IL_042a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0431: Expected O, but got Unknown
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Expected O, but got Unknown
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Expected O, but got Unknown
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Expected O, but got Unknown
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Expected O, but got Unknown
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Expected O, but got Unknown
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Expected O, but got Unknown
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Expected O, but got Unknown
		//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Expected O, but got Unknown
		warnstring = "";
		string warnstring2 = "";
		if (XmlFileName.Trim().Length == 0)
		{
			XmlFileName = "\\temp\\formatxml.xml";
		}
		if (MapName.Trim().Length == 0)
		{
			MapName = "test";
		}
		if (WorkBookName.Trim().Length == 0)
		{
			WorkBookName = "c:\\temp\\FormatExcel.xls";
		}
		Application oExcel = null;
		Workbook theWorkbook = null;
		try
		{
			if (!OpenExcelWithWorkBook(ref oExcel, WorkBookName, out theWorkbook, showExcel, out warnstring2))
			{
				warnstring = "Error Importing XML with stats - " + warnstring2;
				return false;
			}
			Worksheet val = (Worksheet)((_Workbook)theWorkbook).Sheets.Add(Type.Missing, Type.Missing, Type.Missing, (object)TemplateFileName);
			Range val2 = (Range)((_Worksheet)val).Cells[(object)65536, (object)1];
			val2 = val2[(XlDirection)(-4162)][(XlDirection)(-4161)];
			int column = val2.Column;
			int row = val2.Row;
			Range val3 = (Range)((_Worksheet)val).Cells[(object)1, (object)(column + 1)];
			structRangeProperty defProperty = default(structRangeProperty);
			defProperty.WrapText = val3.WrapText;
			defProperty.ColumnWidth = val3.ColumnWidth;
			defProperty.HorizontalAlignment = val3.HorizontalAlignment;
			defProperty.VerticalAlignment = val3.VerticalAlignment;
			defProperty.LineStyle = val3.Borders.LineStyle;
			Range val4 = (Range)((_Worksheet)val).Cells[(object)1, (object)2];
			val4.Select();
			int num = DataStartCol - 1;
			for (int i = 0; i < num; i++)
			{
				val4.EntireColumn.Insert((object)(XlDirection)(-4161), Type.Missing);
			}
			val4 = (Range)((_Worksheet)val).Cells[(object)65536, (object)1];
			val4 = val4[(XlDirection)(-4162)][(object)1, (object)1];
			val4[(XlDirection)(-4159)][(object)0, (object)0].Value2 = "LL";
			int lLRow = row + 1;
			val4[(XlDirection)(-4159)][(object)1, (object)0].Value2 = "UL";
			int uLRow = row + 2;
			int num2 = row + 4;
			XmlMap val5 = default(XmlMap);
			((_Workbook)((_Application)oExcel).ActiveWorkbook).XmlImport(XmlFileName, ref val5, (object)false, (object)(Range)((_Worksheet)val).Cells[(object)num2, (object)1]);
			((_Workbook)((_Application)oExcel).ActiveWorkbook).Save();
			val4 = (Range)((_Worksheet)val).Cells[(object)num2, (object)1];
			val4 = val4[(XlDirection)(-4161)];
			int column2 = val4.Column;
			val4 = (Range)((_Worksheet)val).Cells[(object)(row + 1), (object)(column + num)];
			int num3 = column2 - (column + num) + 1;
			val4 = val4[(object)2, (object)num3];
			val4[Type.Missing] = LimitsArray;
			try
			{
				for (int j = 1; j <= row; j++)
				{
					val2 = ((_Worksheet)val)[((_Worksheet)val).Cells[(object)j, (object)(column + num)], ((_Worksheet)val).Cells[(object)j, (object)(column + num)]];
					val2.Select();
					val2.AutoFill(((_Worksheet)val)[((_Worksheet)val).Cells[(object)j, (object)(column + num)], ((_Worksheet)val).Cells[(object)j, (object)column2]], (XlAutoFillType)0);
				}
			}
			catch
			{
			}
			val4 = (Range)((_Worksheet)val).Cells[(object)12, (object)1];
			string text = val4.Value2.ToString();
			if (text.ToLower().Trim() == "units of measure" && UnitLabels != null)
			{
				val4 = (Range)((_Worksheet)val).Cells[(object)12, (object)(column + num - 1)];
				val4 = val4[(object)1, (object)UnitLabels.Length];
				val4[(object)Missing.Value] = UnitLabels;
			}
			val4 = (Range)((_Worksheet)val).Cells[(object)num2, (object)1];
			val4 = val4[(XlDirection)(-4121)];
			int row2 = val4.Row;
			HighlightDataWide highlightDataWide = default(HighlightDataWide);
			highlightDataWide.DataStartCol = column + num;
			highlightDataWide.DataEndCol = column2;
			highlightDataWide.DataEndRow = row2;
			highlightDataWide.DataRow = num2;
			highlightDataWide.LLRow = lLRow;
			highlightDataWide.ULRow = uLRow;
			highlightDataWide.InputSheet = val;
			highlightDataWide.oExcel = oExcel;
			highlightDataWide.defProperty = defProperty;
			if (!IncludeCharts)
			{
				if (DoHiglight)
				{
					ThreadPool.QueueUserWorkItem(HighlightRowsInWideView, highlightDataWide);
				}
			}
			else
			{
				if (DoHiglight)
				{
					HighlightRowsInWideView(highlightDataWide);
				}
				StartChart(theWorkbook, val);
			}
			((_Application)oExcel).Visible = false;
			((_Application)oExcel).Visible = true;
			((_Application)oExcel).UserControl = true;
			((_Workbook)theWorkbook).Save();
		}
		catch (Exception ex)
		{
			warnstring = "Error Importing XML with Stats: " + ex.Message;
			return false;
		}
		return true;
	}

	public static bool IVImportXmlinExcelWithStats(string MapName, string WorkBookName, string XmlFileName, double[,] LimitsArray, string TemplateFileName, int DataStartCol, bool IncludeCharts, bool DoHiglight, string[] UnitLabels, bool plotyield, string sheetname, bool showExcel, out string warnstring)
	{
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Expected O, but got Unknown
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Expected O, but got Unknown
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Expected O, but got Unknown
		//IL_0482: Unknown result type (might be due to invalid IL or missing references)
		//IL_0489: Expected O, but got Unknown
		//IL_07b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ba: Expected O, but got Unknown
		//IL_0819: Unknown result type (might be due to invalid IL or missing references)
		//IL_0820: Expected O, but got Unknown
		//IL_086c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0873: Expected O, but got Unknown
		//IL_0891: Unknown result type (might be due to invalid IL or missing references)
		//IL_0898: Expected O, but got Unknown
		//IL_0918: Unknown result type (might be due to invalid IL or missing references)
		//IL_091f: Expected O, but got Unknown
		//IL_0514: Unknown result type (might be due to invalid IL or missing references)
		//IL_051b: Expected O, but got Unknown
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_0278: Expected O, but got Unknown
		//IL_031e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: Expected O, but got Unknown
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0353: Expected O, but got Unknown
		//IL_0388: Unknown result type (might be due to invalid IL or missing references)
		//IL_038f: Expected O, but got Unknown
		//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d6: Expected O, but got Unknown
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Expected O, but got Unknown
		//IL_05e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ec: Expected O, but got Unknown
		//IL_0622: Unknown result type (might be due to invalid IL or missing references)
		//IL_0629: Expected O, but got Unknown
		//IL_0640: Unknown result type (might be due to invalid IL or missing references)
		//IL_0647: Expected O, but got Unknown
		//IL_06f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f9: Expected O, but got Unknown
		warnstring = "";
		string warnstring2 = "";
		if (XmlFileName.Trim().Length == 0)
		{
			XmlFileName = "\\temp\\formatxml.xml";
		}
		if (MapName.Trim().Length == 0)
		{
			MapName = "test";
		}
		if (WorkBookName.Trim().Length == 0)
		{
			WorkBookName = "c:\\temp\\FormatExcel.xls";
		}
		Application oExcel = null;
		Workbook theWorkbook = null;
		try
		{
			if (!OpenExcelWithWorkBook(ref oExcel, WorkBookName, out theWorkbook, showExcel, out warnstring2))
			{
				warnstring = "Error Importing IV XML - " + warnstring2;
				return false;
			}
			Worksheet val = (Worksheet)((_Workbook)theWorkbook).Sheets.Add(Type.Missing, Type.Missing, Type.Missing, (object)TemplateFileName);
			string text = "DT " + sheetname;
			try
			{
				text = text + " " + DateTime.Now.ToString();
				text = text.Replace("/", "");
				text = text.Replace(":", "");
				((_Worksheet)val).Name = text;
			}
			catch
			{
				text = DateTime.Now.ToString();
				text = text.Replace("/", "");
				text = text.Replace(":", "");
				((_Worksheet)val).Name = text;
			}
			Range val2 = (Range)((_Worksheet)val).Cells[(object)65536, (object)1];
			val2 = val2[(XlDirection)(-4162)][(XlDirection)(-4161)];
			int column = val2.Column;
			int row = val2.Row;
			Range val3 = (Range)((_Worksheet)val).Cells[(object)1, (object)(column + 1)];
			structRangeProperty defProperty = default(structRangeProperty);
			defProperty.WrapText = val3.WrapText;
			defProperty.ColumnWidth = val3.ColumnWidth;
			defProperty.HorizontalAlignment = val3.HorizontalAlignment;
			defProperty.VerticalAlignment = val3.VerticalAlignment;
			defProperty.LineStyle = val3.Borders.LineStyle;
			Range val4 = (Range)((_Worksheet)val).Cells[(object)1, (object)2];
			val4.Select();
			int num = DataStartCol - 1;
			for (int i = 0; i < num; i++)
			{
				val4.EntireColumn.Insert((object)(XlDirection)(-4161), Type.Missing);
			}
			val4 = (Range)((_Worksheet)val).Cells[(object)65536, (object)1];
			val4 = val4[(XlDirection)(-4162)][(object)1, (object)1];
			val4[(XlDirection)(-4159)][(object)0, (object)0].Value2 = "LL";
			int lLRow = row + 1;
			val4[(XlDirection)(-4159)][(object)1, (object)0].Value2 = "UL";
			int uLRow = row + 2;
			int num2 = row + 4;
			XmlMap val5 = default(XmlMap);
			((_Workbook)((_Application)oExcel).ActiveWorkbook).XmlImport(XmlFileName, ref val5, (object)false, (object)(Range)((_Worksheet)val).Cells[(object)num2, (object)1]);
			((_Workbook)((_Application)oExcel).ActiveWorkbook).Save();
			val4 = (Range)((_Worksheet)val).Cells[(object)num2, (object)1];
			val4 = val4[(XlDirection)(-4161)];
			int column2 = val4.Column;
			val4 = (Range)((_Worksheet)val).Cells[(object)(row + 1), (object)(column + num)];
			int num3 = column2 - (column + num) + 1;
			val4 = val4[(object)2, (object)num3];
			val4[Type.Missing] = LimitsArray;
			try
			{
				for (int j = 1; j <= row; j++)
				{
					val2 = ((_Worksheet)val)[((_Worksheet)val).Cells[(object)j, (object)(column + num)], ((_Worksheet)val).Cells[(object)j, (object)(column + num)]];
					val2.Select();
					val2.AutoFill(((_Worksheet)val)[((_Worksheet)val).Cells[(object)j, (object)(column + num)], ((_Worksheet)val).Cells[(object)j, (object)column2]], (XlAutoFillType)0);
				}
			}
			catch
			{
			}
			val4 = (Range)((_Worksheet)val).Cells[(object)12, (object)1];
			string text2 = val4.Value2.ToString();
			if (text2.ToLower().Trim() == "units of measure" && UnitLabels != null)
			{
				val4 = (Range)((_Worksheet)val).Cells[(object)12, (object)(column + num)];
				val4 = val4[(object)1, (object)UnitLabels.Length];
				val4[(object)Missing.Value] = UnitLabels;
			}
			val4 = (Range)((_Worksheet)val).Cells[(object)num2, (object)1];
			val4 = val4[(XlDirection)(-4121)];
			int row2 = val4.Row;
			HighlightDataWide highlightDataWide = default(HighlightDataWide);
			highlightDataWide.DataStartCol = column + num;
			highlightDataWide.DataEndCol = column2;
			highlightDataWide.DataEndRow = row2;
			highlightDataWide.DataRow = num2;
			highlightDataWide.LLRow = lLRow;
			highlightDataWide.ULRow = uLRow;
			highlightDataWide.InputSheet = val;
			highlightDataWide.oExcel = oExcel;
			highlightDataWide.defProperty = defProperty;
			if (!IncludeCharts)
			{
				if (DoHiglight)
				{
					ThreadPool.QueueUserWorkItem(HighlightRowsInWideView, highlightDataWide);
				}
			}
			else
			{
				if (DoHiglight)
				{
					HighlightRowsInWideView(highlightDataWide);
				}
				StartChart(theWorkbook, val);
			}
			if (plotyield)
			{
				Range val6 = (Range)((_Worksheet)val).Cells[(object)14, (object)1];
				string text3 = val6.Value2.ToString();
				if (text3 == "Yield")
				{
					Range val7 = (Range)((_Worksheet)val).Cells[(object)1, (object)1];
					Range val8 = (Range)((_Worksheet)val).Cells[(object)1, (object)1];
					val7 = val7[((_Worksheet)val).Cells[(object)15, (object)(column + num)], ((_Worksheet)val).Cells[(object)15, (object)(column + num + num3 - 1)]];
					val8 = val8[((_Worksheet)val).Cells[(object)num2, (object)(column + num)], ((_Worksheet)val).Cells[(object)num2, (object)(column + num + num3 - 1)]];
					try
					{
						Worksheet val9 = (Worksheet)((_Workbook)theWorkbook).Sheets.Add((object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value);
						string text4 = sheetname;
						try
						{
							text4 = "CH " + sheetname + " " + DateTime.Now.ToString();
							text4 = text4.Replace("/", "");
							text4 = text4.Replace(":", "");
							((_Worksheet)val9).Name = text4;
						}
						catch
						{
							text4 = "CH " + DateTime.Now.ToString();
							text4 = text4.Replace("/", "");
							text4 = text4.Replace(":", "");
							((_Worksheet)val9).Name = text4;
						}
						ChartObjects val10 = (ChartObjects)((_Worksheet)val9).ChartObjects((object)Missing.Value);
						ChartObject val11 = val10.Add(150.0, 20.0, 640.0, 480.0);
						Chart chart = val11.Chart;
						((_Chart)chart).SetSourceData(val7, (object)"xlRows");
						((_Chart)val11.Chart).ChartType = (XlChartType)51;
						Series val12 = (Series)((_Chart)chart).SeriesCollection((object)1);
						val12.XValues = val8;
						val12.Name = "Failure Rate";
						val12.Interior.ColorIndex = 3;
						((_Chart)chart).PlotArea.Interior.ColorIndex = 2;
						Axis val13 = (Axis)((_Chart)chart).Axes((object)(XlAxisType)1, (XlAxisGroup)1);
						val13.HasMinorGridlines = false;
						val13.HasMajorGridlines = false;
						Axis val14 = (Axis)((_Chart)chart).Axes((object)(XlAxisType)2, (XlAxisGroup)1);
						val14.HasMinorGridlines = false;
						val14.HasMajorGridlines = false;
						try
						{
							((_Chart)chart).HasTitle = true;
							((_Chart)chart).ChartTitle.Text = "Failure Rate - " + sheetname + " " + DateTime.Now.ToString();
						}
						catch (Exception ex)
						{
							MessageBox.Show(ex.Message, "QTM Data Manager");
						}
						string text5 = "Back to Main Sheet";
						Range val15 = (Range)((_Worksheet)val9).Cells[(object)1, (object)1];
						val15.Hyperlinks.Add((object)val15, "", (object)val6[(object)true, (object)true, (XlReferenceStyle)(-4150), (object)true, (object)true], (object)"", (object)text5);
						val15.EntireColumn.ColumnWidth = text5.Length;
						val6.Hyperlinks.Add((object)val6, "", (object)val15[(object)true, (object)true, (XlReferenceStyle)(-4150), (object)true, (object)true], (object)"", (object)val6.Value2.ToString());
					}
					catch (Exception ex2)
					{
						warnstring = "Error Importing IV XML with Stats - " + ex2.Message;
						return false;
					}
				}
			}
			((_Application)oExcel).Visible = false;
			((_Application)oExcel).Visible = true;
			((_Application)oExcel).UserControl = true;
			((_Workbook)theWorkbook).Save();
		}
		catch (Exception ex3)
		{
			warnstring = "Error Importing IV XML - " + ex3.Message;
			return false;
		}
		return true;
	}

	public static bool CreateBoxChart(string WorkbookName, string WorksheetName, string Q1CSVData, string MinCSVData, string MedianCSVData, string MaxCSVData, string Q3CSVData, string MeanCSVData, string XAxisLabelsCSV, double smallestMin, double highestMax, string chartTitle, string ParamName, string UpperLimit, string LowerLimit, int NumberOfPlots, bool showExcel, out string warnstring)
	{
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Expected O, but got Unknown
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Expected O, but got Unknown
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Expected O, but got Unknown
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Expected O, but got Unknown
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Expected O, but got Unknown
		warnstring = "";
		string warnstring2 = "";
		try
		{
			Application oExcel = null;
			Workbook theWorkbook = null;
			if (WorkbookName.Length > 0)
			{
				if (!OpenExcelWithWorkBook(ref oExcel, WorkbookName, out theWorkbook, showExcel, out warnstring2))
				{
					warnstring = "Error Creating Box Chart - " + warnstring2;
					return false;
				}
			}
			else if (!OpenExcelWithWorkBook(ref oExcel, "c:\\temp\\FormatExcel.xls", out theWorkbook, showExcel, out warnstring))
			{
				warnstring = "Error Creating Box Chart - " + warnstring2;
				return false;
			}
			string text = ((WorksheetName.Length <= 0) ? "Box - New Sheet" : ("Box - " + WorksheetName));
			((_Application)oExcel).Visible = false;
			Worksheet val = null;
			try
			{
				for (int i = 1; i <= ((_Workbook)theWorkbook).Worksheets.Count; i++)
				{
					Worksheet val2 = (Worksheet)((_Workbook)theWorkbook).Worksheets[(object)i];
					if (((_Worksheet)val2).Name == text)
					{
						val = (Worksheet)((_Workbook)theWorkbook).Worksheets[(object)i];
						i = ((_Workbook)theWorkbook).Worksheets.Count + 1;
					}
				}
				if (val == null)
				{
					val = (Worksheet)((_Workbook)theWorkbook).Worksheets.Add((object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value);
					((_Worksheet)val).Name = text;
				}
			}
			catch
			{
				val = (Worksheet)((_Workbook)theWorkbook).Worksheets.Add((object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value);
				((_Worksheet)val).Name = text;
			}
			BoxWhiskerData boxWhiskerData = new BoxWhiskerData();
			boxWhiskerData.ChartTitle = chartTitle;
			boxWhiskerData.YAxisTitle = ParamName;
			boxWhiskerData.CategoryXLabels = XAxisLabelsCSV;
			boxWhiskerData.CurrentWorkBook = theWorkbook;
			boxWhiskerData.CurrentWorkSheet = val;
			boxWhiskerData.WidthPoint = 450;
			boxWhiskerData.HeightPoint = boxWhiskerData.WidthPoint * 3 / 4;
			boxWhiskerData.NumberOfPlots = NumberOfPlots;
			boxWhiskerData.MaxSeries = new structDataSeries("Max", MaxCSVData);
			boxWhiskerData.MedianSeries = new structDataSeries("Median", MedianCSVData);
			boxWhiskerData.MinSeries = new structDataSeries("Min", MinCSVData);
			boxWhiskerData.Quartlie1Series = new structDataSeries("Q1", Q1CSVData);
			boxWhiskerData.Quartlie3Series = new structDataSeries("Q3", Q3CSVData);
			boxWhiskerData.MeanSeries = new structDataSeries("Mean", MeanCSVData);
			boxWhiskerData.UpperLimit = new structDataSeries("UL", UpperLimit);
			boxWhiskerData.LowerLimit = new structDataSeries("LL", LowerLimit);
			ChartObjects val3 = (ChartObjects)((_Worksheet)val).ChartObjects((object)Missing.Value);
			if (val3.Count > 0)
			{
				int num = val3.Count % 2;
				int num2 = val3.Count / 2;
				boxWhiskerData.TopPoint = num2 * boxWhiskerData.HeightPoint;
				boxWhiskerData.LeftPoint = num * boxWhiskerData.WidthPoint;
			}
			else
			{
				boxWhiskerData.TopPoint = 1;
				boxWhiskerData.LeftPoint = 1;
			}
			double num3 = highestMax + Math.Abs(0.1 * highestMax);
			double num4 = smallestMin - Math.Abs(0.1 * smallestMin);
			boxWhiskerData.MaximumScale = Math.Round(num3, 3);
			boxWhiskerData.MinimumScale = Math.Round(num4, 3);
			double value = Math.Abs((num3 - num4) / 10.0);
			value = Math.Round(value, 3);
			if (value == 0.0)
			{
				value = 0.1;
			}
			boxWhiskerData.StepSize = value;
			AddBoxChart(boxWhiskerData, out var scrollRow, out var scrollCol);
			((_Worksheet)val).Activate();
			Window activeWindow = ((_Application)oExcel).ActiveWindow;
			activeWindow.ScrollRow = scrollRow;
			activeWindow.ScrollColumn = scrollCol;
			((_Application)oExcel).Visible = true;
			return true;
		}
		catch (Exception ex)
		{
			warnstring = "Error Creating Box Chart - " + ex.Message;
			return false;
		}
	}

	public static void AddBoxChart(BoxWhiskerData bwData, out int scrollRow, out int scrollCol)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		//IL_0365: Unknown result type (might be due to invalid IL or missing references)
		//IL_036c: Expected O, but got Unknown
		//IL_0497: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b0: Expected O, but got Unknown
		//IL_052c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0533: Expected O, but got Unknown
		//IL_05bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c4: Expected O, but got Unknown
		//IL_0460: Unknown result type (might be due to invalid IL or missing references)
		//IL_0467: Expected O, but got Unknown
		Worksheet currentWorkSheet = bwData.CurrentWorkSheet;
		ChartObjects val = (ChartObjects)((_Worksheet)currentWorkSheet).ChartObjects((object)Missing.Value);
		ChartObject val2 = val.Add((double)bwData.LeftPoint, (double)bwData.TopPoint, (double)bwData.WidthPoint, (double)bwData.HeightPoint);
		Chart chart = val2.Chart;
		((_Chart)chart).ChartType = (XlChartType)65;
		((_Chart)chart).PlotBy = (XlRowCol)1;
		SeriesCollection val3 = (SeriesCollection)((_Chart)chart).SeriesCollection((object)Missing.Value);
		Series val4 = val3.NewSeries();
		val4.Name = bwData.Quartlie1Series.Name;
		val4.Values = bwData.Quartlie1Series.Values;
		val4.XValues = bwData.CategoryXLabels;
		val4.Smooth = false;
		val4.Border.LineStyle = (object)(XlLineStyle)(-4142);
		Series val5 = val3.NewSeries();
		val5.Name = bwData.MinSeries.Name;
		val5.Values = bwData.MinSeries.Values;
		val5.Smooth = false;
		val5.Border.LineStyle = (object)(XlLineStyle)(-4142);
		Series val6 = val3.NewSeries();
		val6.Name = bwData.MedianSeries.Name;
		val6.Values = bwData.MedianSeries.Values;
		val6.Smooth = false;
		val6.Border.LineStyle = (object)(XlLineStyle)(-4142);
		val6.MarkerBackgroundColorIndex = (XlColorIndex)1;
		val6.MarkerForegroundColorIndex = (XlColorIndex)1;
		val6.MarkerStyle = (XlMarkerStyle)3;
		val6.Smooth = false;
		val6.MarkerSize = 5;
		val6.Shadow = false;
		Series val7 = val3.NewSeries();
		val7.Name = bwData.MeanSeries.Name;
		val7.Values = bwData.MeanSeries.Values;
		val7.Smooth = false;
		val7.Border.LineStyle = (object)(XlLineStyle)(-4142);
		val7.MarkerBackgroundColorIndex = (XlColorIndex)10;
		val7.MarkerForegroundColorIndex = (XlColorIndex)10;
		val7.MarkerStyle = (XlMarkerStyle)8;
		val7.Smooth = false;
		val7.MarkerSize = 5;
		val7.Shadow = false;
		Series val8 = val3.NewSeries();
		val8.Name = bwData.MaxSeries.Name;
		val8.Values = bwData.MaxSeries.Values;
		val8.Smooth = false;
		val8.Border.LineStyle = (object)(XlLineStyle)(-4142);
		Series val9 = val3.NewSeries();
		val9.Name = bwData.Quartlie3Series.Name;
		val9.Values = bwData.Quartlie3Series.Values;
		val9.Smooth = false;
		val9.Border.LineStyle = (object)(XlLineStyle)(-4142);
		Series val10 = val3.NewSeries();
		try
		{
			val10.Name = bwData.UpperLimit.Name;
			val10.Values = bwData.UpperLimit.Values;
			val10.Smooth = false;
			val10.Border.LineStyle = (object)(XlLineStyle)(-4142);
			val10.ChartType = (XlChartType)75;
			val10.ErrorBar((XlErrorBarDirection)(-4168), (XlErrorBarInclude)1, (XlErrorBarType)1, (object)bwData.NumberOfPlots, (object)Missing.Value);
			val10.ErrorBars.Border.LineStyle = (object)(XlLineStyle)1;
			val10.ErrorBars.Border.ColorIndex = (object)(XlColorIndex)3;
			val10.ErrorBars.Border.Weight = (object)(XlBorderWeight)2;
			LegendEntry val11 = (LegendEntry)((_Chart)chart).Legend.LegendEntries((object)(val3.Count - 1));
			val11.LegendKey.Border.ColorIndex = (object)(XlColorIndex)3;
		}
		catch
		{
			val10.Delete();
		}
		Series val12 = val3.NewSeries();
		try
		{
			val12.Name = bwData.LowerLimit.Name;
			val12.Values = bwData.LowerLimit.Values;
			val12.Smooth = false;
			val12.Border.LineStyle = (object)(XlLineStyle)(-4142);
			val12.ChartType = (XlChartType)75;
			val12.ErrorBar((XlErrorBarDirection)(-4168), (XlErrorBarInclude)1, (XlErrorBarType)1, (object)bwData.NumberOfPlots, (object)Missing.Value);
			val12.ErrorBars.Border.LineStyle = (object)(XlLineStyle)1;
			val12.ErrorBars.Border.ColorIndex = (object)(XlColorIndex)41;
			val12.ErrorBars.Border.Weight = (object)(XlBorderWeight)2;
			LegendEntry val13 = (LegendEntry)((_Chart)chart).Legend.LegendEntries((object)val3.Count);
			val13.LegendKey.Border.ColorIndex = (object)(XlColorIndex)41;
		}
		catch
		{
			val12.Delete();
		}
		_ = (ChartGroups)((_Chart)chart).ChartGroups((object)Missing.Value);
		ChartGroup val14 = (ChartGroup)((_Chart)chart).ChartGroups((object)1);
		val14.HasDropLines = false;
		val14.HasHiLoLines = true;
		val14.HasUpDownBars = true;
		val14.GapWidth = 150;
		try
		{
			val14.UpBars.Interior.ColorIndex = (object)(XlColorIndex)40;
			val14.UpBars.Interior.PatternColorIndex = (object)(XlColorIndex)1;
			val14.UpBars.Interior.Pattern = (object)(XlPattern)1;
		}
		catch
		{
		}
		Axis val15 = (Axis)((_Chart)chart).Axes((object)(XlAxisType)2, (XlAxisGroup)1);
		val15.HasMajorGridlines = false;
		val15.HasMinorGridlines = false;
		val15.HasDisplayUnitLabel = true;
		val15.TickLabels.Font.Size = 8;
		val15.MinimumScale = bwData.MinimumScale;
		val15.MaximumScale = bwData.MaximumScale;
		val15.MajorUnit = bwData.StepSize;
		val15.HasTitle = true;
		val15.AxisTitle.Text = bwData.YAxisTitle;
		val15.CrossesAt = bwData.MinimumScale;
		Axis val16 = (Axis)((_Chart)chart).Axes((object)(XlAxisType)1, (XlAxisGroup)1);
		val16.HasMajorGridlines = false;
		val16.HasMinorGridlines = false;
		val16.TickLabels.Font.Size = 8;
		val16.TickLabels.Alignment = -4108;
		val16.TickLabels.Offset = 100;
		val16.TickLabels.Orientation = (XlTickLabelOrientation)(-4128);
		try
		{
			((_Chart)chart).HasTitle = true;
			((_Chart)chart).ChartTitle.Text = bwData.ChartTitle + "\n " + DateTime.Now.ToString();
			((_Chart)chart).ChartTitle.Font.Size = 10;
			((_Chart)chart).PlotArea.Interior.ColorIndex = (object)(XlColorIndex)2;
			((_Chart)chart).PlotArea.Interior.PatternColorIndex = (object)(XlColorIndex)1;
			((_Chart)chart).PlotArea.Interior.Pattern = (object)(XlPattern)1;
		}
		catch
		{
		}
		try
		{
			scrollRow = val2.TopLeftCell.Row;
		}
		catch
		{
			scrollRow = 1;
		}
		try
		{
			scrollCol = val2.TopLeftCell.Column;
		}
		catch
		{
			scrollCol = 1;
		}
	}

	public static void HighlightRowsInWideView(object InputValues)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Expected O, but got Unknown
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Expected O, but got Unknown
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Expected O, but got Unknown
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Expected O, but got Unknown
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		HighlightDataWide highlightDataWide = (HighlightDataWide)InputValues;
		try
		{
			Worksheet inputSheet = highlightDataWide.InputSheet;
			for (int i = highlightDataWide.DataStartCol; i <= highlightDataWide.DataEndCol; i++)
			{
				Range val = (Range)((_Worksheet)inputSheet).Cells[(object)highlightDataWide.DataRow, (object)i];
				val.WrapText = highlightDataWide.defProperty.WrapText;
				val.ColumnWidth = highlightDataWide.defProperty.ColumnWidth;
				val.HorizontalAlignment = highlightDataWide.defProperty.HorizontalAlignment;
				val.VerticalAlignment = highlightDataWide.defProperty.VerticalAlignment;
				val.Borders.LineStyle = highlightDataWide.defProperty.LineStyle;
				int num = highlightDataWide.DataRow + 1;
				val = (Range)((_Worksheet)inputSheet).Cells[(object)num, (object)i];
				Range val2 = (Range)((_Worksheet)inputSheet).Cells[(object)highlightDataWide.ULRow, (object)i];
				string text = val2[(object)highlightDataWide.LLRow, (object)i, (XlReferenceStyle)1, Type.Missing, Type.Missing];
				Range val3 = (Range)((_Worksheet)inputSheet).Cells[(object)highlightDataWide.LLRow, (object)i];
				string text2 = val3[(object)highlightDataWide.ULRow, (object)i, (XlReferenceStyle)1, Type.Missing, Type.Missing];
				val.FormatConditions.Add((XlFormatConditionType)1, (object)(XlFormatConditionOperator)2, (object)("=" + text), (object)("=" + text2), Type.Missing, Type.Missing, Type.Missing, Type.Missing);
				((FormatCondition)val.FormatConditions[(object)1]).Interior.ColorIndex = 3;
				val.FormatConditions.Add((XlFormatConditionType)1, (object)(XlFormatConditionOperator)3, (object)("=" + text), Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
				((FormatCondition)val.FormatConditions[(object)2]).Interior.ColorIndex = 6;
				val.FormatConditions.Add((XlFormatConditionType)1, (object)(XlFormatConditionOperator)3, (object)("=" + text2), Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
				val.Copy(Type.Missing);
				val2 = ((_Worksheet)inputSheet)[((_Worksheet)inputSheet).Cells[(object)num, (object)i], ((_Worksheet)inputSheet).Cells[(object)highlightDataWide.DataEndRow, (object)i]];
				val2.PasteSpecial((XlPasteType)(-4122), (XlPasteSpecialOperation)(-4142), Type.Missing, Type.Missing);
			}
			((_Workbook)((_Application)highlightDataWide.oExcel).ActiveWorkbook).Save();
		}
		catch
		{
		}
	}

	private static void StartChart(Workbook oWB, Worksheet oSheet)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Expected O, but got Unknown
		ArrayList arrayList = new ArrayList();
		int num = 3;
		int num2 = 0;
		try
		{
			Range val = (Range)((_Worksheet)oSheet).Cells[(object)1048576, (object)1];
			val = val[(XlDirection)(-4162)];
			int row = val.Row;
			val = ((_Worksheet)oSheet)[((_Worksheet)oSheet).Cells[(object)1, (object)1], ((_Worksheet)oSheet).Cells[(object)row, (object)1]];
			object[,] array = (object[,])val.Value2;
			new ArrayList();
			for (int i = 1; i < row; i++)
			{
				if (array[i, 1] != null && array[i, 1].ToString() == "UUT_SN")
				{
					num2 = i;
					break;
				}
			}
			val = (Range)((_Worksheet)oSheet).Cells[(object)num2, (object)1];
			val = val[(XlDirection)(-4161)];
			int column = val.Column;
			val = ((_Worksheet)oSheet)[((_Worksheet)oSheet).Cells[(object)1, (object)1], ((_Worksheet)oSheet).Cells[(object)row, (object)column]];
			array = (object[,])val.Value2;
			ChartDataDetails chartDataDetails = default(ChartDataDetails);
			string text = "";
			string text2 = "";
			string text3 = "";
			string text4 = "";
			string text5 = "";
			chartDataDetails.StartCol = num;
			chartDataDetails.ChartInnerLoop = "";
			for (int j = num; j <= column; j++)
			{
				string text6 = array[num2, j].ToString();
				if (text6.Trim().Length <= 0)
				{
					continue;
				}
				string[] array2 = text6.Split(FormatFunctions.SEP);
				text2 = array2[0];
				text3 = array2[1];
				text5 = ((array2.GetLength(0) <= 2) ? "" : array2[2]);
				text4 = text2 + " " + text3;
				if (text != text4)
				{
					chartDataDetails.ChartParamName = text3;
					chartDataDetails.ChartTestName = text2;
					chartDataDetails.ChartCondName = text5;
					if (text != "")
					{
						chartDataDetails.StopCol = j - 1;
						chartDataDetails.ChartInnerLoop = chartDataDetails.ChartInnerLoop.Remove(chartDataDetails.ChartInnerLoop.LastIndexOf(","), 1);
						arrayList.Add(chartDataDetails);
						chartDataDetails = default(ChartDataDetails);
						chartDataDetails.StartCol = j;
						chartDataDetails.ChartInnerLoop = "";
					}
					text = text4;
				}
				if (text5 != "")
				{
					string[] array3 = text5.Split(FormatFunctions.LOOPS_SEP.ToCharArray());
					chartDataDetails.ChartInnerLoop = chartDataDetails.ChartInnerLoop + array3[array3.GetLength(0) - 1] + ",";
				}
			}
			chartDataDetails.StopCol = column;
			chartDataDetails.ChartInnerLoop = chartDataDetails.ChartInnerLoop.Remove(chartDataDetails.ChartInnerLoop.LastIndexOf(","), 1);
			arrayList.Add(chartDataDetails);
			ArrayList seriesStats = GetSeriesStats(array);
			int num3 = 0;
			foreach (ChartDataDetails item in arrayList)
			{
				try
				{
					num3++;
					CreateChart(oWB, oSheet, item, seriesStats, num3, num2);
				}
				catch
				{
				}
			}
		}
		catch
		{
		}
	}

	private static void CreateChart(Workbook oWB, Worksheet oSheet, ChartDataDetails chartDetail, ArrayList alSeriesNames, int ChartCounter, int ColumnHeaderRow)
	{
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Expected O, but got Unknown
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Expected O, but got Unknown
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Expected O, but got Unknown
		//IL_05ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f1: Expected O, but got Unknown
		//IL_0621: Unknown result type (might be due to invalid IL or missing references)
		//IL_0627: Expected O, but got Unknown
		int startCol = chartDetail.StartCol;
		int stopCol = chartDetail.StopCol;
		Range val = ((_Worksheet)oSheet)[((_Worksheet)oSheet).Cells[(object)1, (object)startCol], ((_Worksheet)oSheet).Cells[(object)alSeriesNames.Count, (object)stopCol]];
		Chart val2 = (Chart)((_Workbook)oWB).Charts.Add((object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value);
		((_Chart)val2).ChartWizard((object)val, (object)(XlChartType)4, (object)Missing.Value, (object)(XlRowCol)1, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value);
		new ArrayList();
		FormatChart(val2, "Channel", chartDetail.ChartParamName);
		((_Chart)val2).ChartTitle.Text = chartDetail.ChartTestName + " " + chartDetail.ChartParamName + ": Stats";
		Series val3 = (Series)((_Chart)val2).SeriesCollection((object)1);
		val3.XValues = chartDetail.ChartInnerLoop;
		for (int i = 0; i < alSeriesNames.Count; i++)
		{
			val3 = (Series)((_Chart)val2).SeriesCollection((object)(i + 1));
			val3.Border.LineStyle = (object)(XlLineStyle)(-4142);
			val3.Name = alSeriesNames[i].ToString();
			switch (val3.Name)
			{
			case "Average":
				val3.MarkerStyle = (XlMarkerStyle)9;
				val3.MarkerForegroundColor = 5;
				val3.MarkerBackgroundColorIndex = (XlColorIndex)(-4142);
				break;
			case "Min":
				val3.MarkerStyle = (XlMarkerStyle)2;
				val3.MarkerForegroundColorIndex = (XlColorIndex)10;
				val3.MarkerBackgroundColorIndex = (XlColorIndex)43;
				val3.MarkerSize = 7;
				break;
			case "Max":
				val3.MarkerStyle = (XlMarkerStyle)3;
				val3.MarkerForegroundColorIndex = (XlColorIndex)10;
				val3.MarkerBackgroundColorIndex = (XlColorIndex)43;
				val3.MarkerSize = 7;
				break;
			case "LL":
				val3.MarkerStyle = (XlMarkerStyle)(-4115);
				val3.MarkerForegroundColorIndex = (XlColorIndex)3;
				val3.MarkerBackgroundColorIndex = (XlColorIndex)3;
				val3.MarkerSize = 12;
				break;
			case "UL":
				val3.MarkerStyle = (XlMarkerStyle)(-4115);
				val3.MarkerForegroundColorIndex = (XlColorIndex)3;
				val3.MarkerBackgroundColorIndex = (XlColorIndex)3;
				val3.MarkerSize = 12;
				break;
			case "Avg-3Sig":
				val3.MarkerStyle = (XlMarkerStyle)(-4142);
				val3.Border.LineStyle = (object)(XlLineStyle)1;
				val3.Border.ColorIndex = (object)(XlColorIndex)3;
				val3.Border.Weight = (object)(XlBorderWeight)(-4138);
				break;
			case "Avg+3Sig":
				val3.MarkerStyle = (XlMarkerStyle)(-4142);
				val3.Border.LineStyle = (object)(XlLineStyle)1;
				val3.Border.ColorIndex = (object)(XlColorIndex)5;
				val3.Border.Weight = (object)(XlBorderWeight)(-4138);
				break;
			}
		}
		((_Chart)val2).Location((XlChartLocation)2, (object)((_Worksheet)oSheet).Name);
		Range topLeftCell;
		if (ChartCounter > 1)
		{
			if (ChartCounter % 2 == 0)
			{
				((_Worksheet)oSheet).Shapes.Item((object)("Chart " + ((_Worksheet)oSheet).Shapes.Count)).Left = ((_Worksheet)oSheet).Shapes.Item((object)("Chart " + (((_Worksheet)oSheet).Shapes.Count - 1))).Width;
				_ = ((_Worksheet)oSheet).Shapes.Item((object)("Chart " + (((_Worksheet)oSheet).Shapes.Count - 1))).Top;
				((_Worksheet)oSheet).Shapes.Item((object)("Chart " + ((_Worksheet)oSheet).Shapes.Count)).Top = ((_Worksheet)oSheet).Shapes.Item((object)("Chart " + (((_Worksheet)oSheet).Shapes.Count - 1))).Top;
			}
			else
			{
				Range val4 = ((_Worksheet)oSheet)[(object)"A1", (object)Missing.Value];
				((_Worksheet)oSheet).Shapes.Item((object)("Chart " + ((_Worksheet)oSheet).Shapes.Count)).Left = (float)(double)val4.Left;
				float top = ((_Worksheet)oSheet).Shapes.Item((object)("Chart " + (((_Worksheet)oSheet).Shapes.Count - 1))).Top;
				((_Worksheet)oSheet).Shapes.Item((object)("Chart " + ((_Worksheet)oSheet).Shapes.Count)).Top = top + ((_Worksheet)oSheet).Shapes.Item((object)("Chart " + (((_Worksheet)oSheet).Shapes.Count - 1))).Height;
			}
			((_Worksheet)oSheet).Shapes.Item((object)("Chart " + ((_Worksheet)oSheet).Shapes.Count)).ScaleHeight(1.03f, (MsoTriState)0, (object)Missing.Value);
			topLeftCell = ((_Worksheet)oSheet).Shapes.Item((object)("Chart " + ((_Worksheet)oSheet).Shapes.Count)).TopLeftCell;
		}
		else
		{
			Range val5 = (Range)((_Worksheet)oSheet).Cells[(object)1048576, (object)1];
			val5 = val5[(XlDirection)(-4162)];
			int row = val5.Row;
			Range val6 = (Range)((_Worksheet)oSheet).Rows[(object)(row + 2), (object)Missing.Value];
			((_Worksheet)oSheet).Shapes.Item((object)((_Worksheet)oSheet).Shapes.Count).Top = (float)(double)val6.Top;
			Range val4 = ((_Worksheet)oSheet)[(object)"A1", (object)Missing.Value];
			((_Worksheet)oSheet).Shapes.Item((object)((_Worksheet)oSheet).Shapes.Count).Left = (float)(double)val4.Left;
			((_Worksheet)oSheet).Shapes.Item((object)((_Worksheet)oSheet).Shapes.Count).ScaleHeight(1.03f, (MsoTriState)0, (object)Missing.Value);
			topLeftCell = ((_Worksheet)oSheet).Shapes.Item((object)((_Worksheet)oSheet).Shapes.Count).TopLeftCell;
		}
		Range val7 = ((_Worksheet)oSheet)[((_Worksheet)oSheet).Cells[(object)ColumnHeaderRow, (object)startCol], ((_Worksheet)oSheet).Cells[(object)ColumnHeaderRow, (object)stopCol]];
		int num = topLeftCell.Row + 23;
		((_Worksheet)oSheet).Hyperlinks.Add((object)val7, "", (object)("'" + ((_Worksheet)oSheet).Name + "'!A" + num), (object)Missing.Value, (object)Missing.Value);
	}

	private static void FormatChart(Chart oChart, string XAxisTitle, string YAxisTitle)
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Expected O, but got Unknown
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Expected O, but got Unknown
		((_Chart)oChart).HasDataTable = true;
		((_Chart)oChart).DataTable.Font.Size = 7;
		((_Chart)oChart).PlotArea.Interior.ColorIndex = 2;
		((_Chart)oChart).HasLegend = false;
		((_Chart)oChart).HasTitle = true;
		((_Chart)oChart).ChartTitle.Font.Size = 10;
		Axis val = (Axis)((_Chart)oChart).Axes((object)(XlAxisType)1, (XlAxisGroup)1);
		val.HasTitle = true;
		val.AxisTitle.Font.Size = 9;
		val.HasMajorGridlines = true;
		val.AxisTitle.Font.Bold = false;
		val.Border.LineStyle = (object)(XlLineStyle)(-4142);
		val.AxisTitle.Text = XAxisTitle;
		val.MajorGridlines.Border.ColorIndex = 15;
		val.MajorGridlines.Border.Weight = (object)(XlBorderWeight)1;
		val.MajorGridlines.Border.LineStyle = (object)(XlLineStyle)1;
		Axis val2 = (Axis)((_Chart)oChart).Axes((object)(XlAxisType)2, (XlAxisGroup)1);
		val2.HasTitle = true;
		val2.AxisTitle.Font.Size = 9;
		val2.AxisTitle.Font.Bold = false;
		val2.TickLabels.Font.Size = 8;
		val2.AxisTitle.Text = YAxisTitle;
		val2.MajorGridlines.Border.ColorIndex = 15;
		val2.MajorGridlines.Border.Weight = (object)(XlBorderWeight)1;
		val2.MajorGridlines.Border.LineStyle = (object)(XlLineStyle)1;
	}

	private static ArrayList GetSeriesStats(object[,] data)
	{
		ArrayList arrayList = new ArrayList();
		for (int i = 1; data[i, 1] != null; i++)
		{
			arrayList.Add(data[i, 1]);
		}
		return arrayList;
	}

	public static void CloseExcel(bool forceclose)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		try
		{
			Application val = (Application)Marshal.GetActiveObject("Excel.Application");
			if (((_Application)val).Workbooks.Count <= 0)
			{
				((_Application)val).Quit();
			}
			else
			{
				if (!forceclose)
				{
					return;
				}
				foreach (Workbook workbook in ((_Application)val).Workbooks)
				{
					Workbook val2 = workbook;
					((_Workbook)val2).Close((object)false, (object)Missing.Value, (object)Missing.Value);
				}
				((_Application)val).Quit();
			}
		}
		catch
		{
		}
	}
}
