using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using Microsoft.Office.Interop.Excel;

namespace QC.CorpTest.Libraries.ExcelLibrary;

public static class ExcelManager
{
	private static Application objApplication = null;

	private static Workbooks objWorkbooks = null;

	private static Workbook objWorkbook = null;

	private static Sheets objSheets = null;

	private static Worksheet objWorksheet = null;

	private static Range objWorkingRange1 = null;

	private static Range objWorkingRange2 = null;

	private static Range objRange = null;

	private static Chart objChart = null;

	private static Axis objAxis = null;

	private static bool excelOpen = false;

	private static bool newExcelCreated = false;

	private static List<string> newWorkBookList = new List<string>();

	private static Dictionary<string, Dictionary<string, string>> newWorkSheetDictionary = new Dictionary<string, Dictionary<string, string>>();

	private static int[] colorIndexes = new int[9] { 13, 55, 5, 37, 10, 43, 44, 46, 3 };

	private static int[] markerStyles = new int[8] { 8, 2, 3, -4168, 5, -4115, 9, 1 };

	private static CultureInfo originalCultureInfo = null;

	public static bool ExcelOpen => excelOpen;

	public static bool NewExcelCreated => newExcelCreated;

	public static string SelectedWorkBook
	{
		get
		{
			if (objWorkbook != null)
			{
				return ((_Workbook)objWorkbook).Name;
			}
			return "";
		}
	}

	public static string SelectedWorkSheet
	{
		get
		{
			if (objWorksheet != null)
			{
				return ((_Worksheet)objWorksheet).Name;
			}
			return "";
		}
	}

	public static string ConvertCellAddress(string cellAddress, CellAddressType fromCellAddressType, CellAddressType toCellAddressType)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		MapReferenceStyle(fromCellAddressType, out var referenceStyle);
		MapReferenceStyle(toCellAddressType, out var referenceStyle2);
		string result = "";
		if (objApplication != null)
		{
			object obj = ((_Application)objApplication).ConvertFormula((object)cellAddress, referenceStyle, (object)referenceStyle2, (object)(XlReferenceType)1, Type.Missing);
			result = Convert.ToString(obj);
		}
		return result;
	}

	public static DataTable GetDataTableIteratively(ExcelCell startCell, ExcelCell endCell, out string errorMessage)
	{
		errorMessage = "";
		if (objWorksheet == null)
		{
			throw new ExcelException("No Worksheet selected");
		}
		DataTable dataTable = new DataTable();
		for (int i = startCell.ColumnIndex; i <= endCell.ColumnIndex; i++)
		{
			ExcelCell excelCell = new ExcelCell(startCell.RowIndex, i);
			string cellContent = "";
			string errorMessage2 = "";
			GetCellContent(excelCell.GetCellAddressInA1(), cellText: true, out cellContent, out errorMessage2);
			if (cellContent.Length <= 0)
			{
				cellContent = "Column" + i;
			}
			if (errorMessage2.Length > 0)
			{
				errorMessage = errorMessage + ";" + errorMessage2;
			}
			DataColumn column = new DataColumn(cellContent, typeof(string));
			dataTable.Columns.Add(column);
		}
		for (int j = startCell.RowIndex + 1; j <= endCell.RowIndex; j++)
		{
			DataRow dataRow = dataTable.NewRow();
			for (int k = startCell.ColumnIndex; k <= endCell.ColumnIndex; k++)
			{
				ExcelCell excelCell2 = new ExcelCell(j, k);
				string cellContent2 = "";
				string errorMessage3 = "";
				GetCellContent(excelCell2.GetCellAddressInA1(), cellText: true, out cellContent2, out errorMessage3);
				int num = k - startCell.ColumnIndex;
				if (num < dataTable.Columns.Count)
				{
					dataRow[num] = cellContent2;
				}
				if (errorMessage3.Length > 0)
				{
					errorMessage = errorMessage + ";" + errorMessage3;
				}
			}
			dataTable.Rows.Add(dataRow);
		}
		return dataTable;
	}

	public static int GetDataTable(string fileName, string sheetName, string startCell, string endCell, out DataTable dataTable, out string errorMessage)
	{
		errorMessage = "";
		dataTable = null;
		try
		{
			dataTable = new DataTable();
			int num = 0;
			string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=\"Excel 8.0;IMEX=1;HDR=Yes\"";
			string cmdText = "";
			if (startCell.Length > 0)
			{
				if (endCell.Length > 0)
				{
					cmdText = "SELECT * From [" + sheetName + "$" + startCell + ":" + endCell + "]";
				}
			}
			else
			{
				cmdText = "SELECT * From [" + sheetName + "$]";
			}
			OleDbConnection oleDbConnection = new OleDbConnection(connectionString);
			OleDbCommand selectCommand = new OleDbCommand(cmdText, oleDbConnection);
			OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter(selectCommand);
			try
			{
				oleDbConnection.Open();
			}
			catch (Exception ex)
			{
				num = -4001;
				errorMessage = num + ":Error opening connection to the workbook - " + ex.Message;
			}
			if (num < 0)
			{
				return num;
			}
			try
			{
				oleDbDataAdapter.Fill(dataTable);
			}
			catch (Exception ex2)
			{
				num = -4002;
				errorMessage = num + ":Error filling the data table - " + ex2.Message;
				dataTable = null;
			}
			finally
			{
				oleDbConnection.Close();
			}
			return num;
		}
		catch (Exception ex3)
		{
			errorMessage = "Error retrieving data table - " + ex3.Message;
			return -4003;
		}
	}

	public static object[,] GetDataAsTwoDimensionalArray(ExcelRange range)
	{
		try
		{
			int num = range.EndCell.RowIndex - range.StartCell.RowIndex + 1;
			int num2 = range.EndCell.ColumnIndex - range.StartCell.ColumnIndex + 1;
			object[,] array = new object[num, num2];
			SelectRange(range);
			return (object[,])objRange.Value2;
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error importing Xml", innerException);
		}
	}

	public static DataTable GetDataTableUsingArray(ExcelRange range, bool firstRowIsHeader)
	{
		try
		{
			object[,] dataAsTwoDimensionalArray = GetDataAsTwoDimensionalArray(range);
			DataTable dataTable = new DataTable();
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			for (int i = 1; i <= dataAsTwoDimensionalArray.GetLength(1); i++)
			{
				int num = 0;
				string text = "";
				text = ((!firstRowIsHeader) ? ("Column" + i) : Convert.ToString(dataAsTwoDimensionalArray[1, i]));
				if (dataTable.Columns.Contains(text))
				{
					text = text + "_" + dictionary[text]++;
				}
				else
				{
					dictionary[text] = num + 1;
				}
				DataColumn column = new DataColumn(text, typeof(object));
				dataTable.Columns.Add(column);
			}
			int num2 = 1;
			if (firstRowIsHeader)
			{
				num2 = 2;
			}
			for (int j = num2; j <= dataAsTwoDimensionalArray.GetLength(0); j++)
			{
				DataRow dataRow = dataTable.NewRow();
				for (int k = 1; k <= dataAsTwoDimensionalArray.GetLength(1); k++)
				{
					dataRow[k - 1] = Convert.ToString(dataAsTwoDimensionalArray[j, k]);
				}
				dataTable.Rows.Add(dataRow);
			}
			return dataTable;
		}
		catch
		{
			throw;
		}
	}

	public static void OpenExcel(bool showexcel)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Expected O, but got Unknown
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		try
		{
			try
			{
				objApplication = (Application)Marshal.GetActiveObject("Excel.Application");
			}
			catch
			{
				objApplication = (Application)new ApplicationClass();
				newExcelCreated = true;
			}
			((_Application)objApplication).Visible = showexcel;
			((_Application)objApplication).DisplayAlerts = false;
			objWorkbooks = ((_Application)objApplication).Workbooks;
			excelOpen = true;
		}
		catch (Exception innerException)
		{
			ExcelException ex = new ExcelException("Error Opening Excel", innerException);
			throw ex;
		}
	}

	public static void ReleaseExcel()
	{
		try
		{
			if (objWorkingRange1 != null)
			{
				Marshal.FinalReleaseComObject(objWorkingRange1);
				objWorkingRange1 = null;
			}
			if (objWorkingRange2 != null)
			{
				Marshal.FinalReleaseComObject(objWorkingRange2);
				objWorkingRange2 = null;
			}
			if (objWorksheet != null)
			{
				Marshal.FinalReleaseComObject(objWorksheet);
				objWorksheet = null;
			}
			if (objSheets != null)
			{
				Marshal.FinalReleaseComObject(objSheets);
				objSheets = null;
			}
			if (objWorkbook != null)
			{
				Marshal.FinalReleaseComObject(objWorkbook);
				objWorkbook = null;
			}
			if (objWorkbooks != null)
			{
				Marshal.FinalReleaseComObject(objWorkbooks);
				objWorkbooks = null;
			}
			if (objApplication != null)
			{
				Marshal.FinalReleaseComObject(objApplication);
				objApplication = null;
				excelOpen = false;
			}
			GC.Collect();
		}
		catch (Exception innerException)
		{
			ExcelException ex = new ExcelException("Error closing Excel", innerException);
			throw ex;
		}
	}

	public static void CloseExcel()
	{
		try
		{
			if (objWorkingRange1 != null)
			{
				Marshal.FinalReleaseComObject(objWorkingRange1);
				objWorkingRange1 = null;
			}
			if (objWorkingRange2 != null)
			{
				Marshal.FinalReleaseComObject(objWorkingRange2);
				objWorkingRange2 = null;
			}
			if (objWorksheet != null)
			{
				Marshal.FinalReleaseComObject(objWorksheet);
				objWorksheet = null;
			}
			if (objSheets != null)
			{
				Marshal.FinalReleaseComObject(objSheets);
				objSheets = null;
			}
			if (objWorkbook != null)
			{
				((_Workbook)objWorkbook).Close((object)false, Type.Missing, Type.Missing);
				Marshal.FinalReleaseComObject(objWorkbook);
				objWorkbook = null;
			}
			if (objWorkbooks != null)
			{
				objWorkbooks.Close();
				Marshal.FinalReleaseComObject(objWorkbooks);
				objWorkbooks = null;
			}
			if (objApplication != null)
			{
				((_Application)objApplication).Workbooks.Close();
				if (newExcelCreated)
				{
					((_Application)objApplication).Quit();
				}
				Marshal.FinalReleaseComObject(objApplication);
				objApplication = null;
				excelOpen = false;
			}
			GC.Collect();
		}
		catch (Exception innerException)
		{
			ExcelException ex = new ExcelException("Error closing Excel", innerException);
			throw ex;
		}
	}

	public static void OpenWorkBook(OpenWorkbookArguments oWkbkArgs)
	{
		try
		{
			bool flag = false;
			List<string> workbookNames = GetWorkbookNames();
			if (workbookNames != null && workbookNames.Contains(oWkbkArgs.Filename))
			{
				flag = true;
			}
			if (flag)
			{
				SelectWorkBook(oWkbkArgs.Filename);
			}
			if (workbookNames.Contains(oWkbkArgs.Filename))
			{
				SelectWorkBook(oWkbkArgs.Filename);
				return;
			}
			if (File.Exists(oWkbkArgs.Filename) && !oWkbkArgs.CreateNew)
			{
				objWorkbook = objWorkbooks.Open(oWkbkArgs.Filename, oWkbkArgs.UpdateLinksAsInteger, oWkbkArgs.ReadOnlyAsBoolean, oWkbkArgs.FormatAsInteger, oWkbkArgs.PasswordAsString, oWkbkArgs.WriteResPasswordAsString, oWkbkArgs.IgnoreReadOnlyRecommendedAsBoolean, ExcelOptionsMapper.GetPlatform(oWkbkArgs.OriginAsString), oWkbkArgs.DelimiterAsString, oWkbkArgs.EditableAsBoolean, oWkbkArgs.NotifyAsBoolean, oWkbkArgs.ConverterAsObject, oWkbkArgs.AddToMruAsBoolean, oWkbkArgs.LocalAsBoolean, ExcelOptionsMapper.GetCorruptLoad(oWkbkArgs.CorruptLoadAsString));
				objSheets = ((_Workbook)objWorkbook).Worksheets;
				return;
			}
			if (oWkbkArgs.CreateNew)
			{
				objWorkbook = objWorkbooks.Add(ExcelOptionsMapper.GetTemplate(oWkbkArgs.TemplateAsString));
				SaveWorkbookArguments saveWorkbookArguments = new SaveWorkbookArguments();
				saveWorkbookArguments.Filename = oWkbkArgs.Filename;
				saveWorkbookArguments.AddToMruAsBoolean = oWkbkArgs.AddToMruAsBoolean;
				saveWorkbookArguments.IgnoreReadOnlyRecommendedAsBoolean = oWkbkArgs.IgnoreReadOnlyRecommendedAsBoolean;
				saveWorkbookArguments.LocalAsBoolean = oWkbkArgs.LocalAsBoolean;
				saveWorkbookArguments.PasswordAsString = oWkbkArgs.PasswordAsString;
				saveWorkbookArguments.WriteResPasswordAsString = oWkbkArgs.WriteResPasswordAsString;
				SaveWorkBook(saveWorkbookArguments);
				objSheets = ((_Workbook)objWorkbook).Worksheets;
				if (!newWorkBookList.Contains(oWkbkArgs.Filename))
				{
					newWorkBookList.Add(oWkbkArgs.Filename);
				}
				return;
			}
			ExcelException ex = new ExcelException("Workbook " + oWkbkArgs.Filename + "does not exist");
			throw ex;
		}
		catch (Exception ex2)
		{
			ExcelException ex3 = new ExcelException("Error opening workbook, " + ex2.Message, ex2);
			throw ex3;
		}
	}

	public static int CloseWorkBook(out string errorMessage)
	{
		errorMessage = "";
		int result = 0;
		try
		{
			if (objWorkbook != null)
			{
				((_Workbook)objWorkbook).Close((object)false, Type.Missing, Type.Missing);
				Marshal.ReleaseComObject(objWorkbook);
				objWorkbook = null;
			}
		}
		catch (Exception ex)
		{
			errorMessage = "Error closing Workbook - " + ex.Message;
			result = -4007;
		}
		return result;
	}

	public static void SelectWorkBook(string workBookFullName)
	{
		if (objWorkbook != null)
		{
			Marshal.ReleaseComObject(objWorkbook);
		}
		objWorkbook = null;
		try
		{
			if (objWorkbooks != null)
			{
				if (objWorkbooks.Count > 0)
				{
					for (int i = 1; i <= objWorkbooks.Count; i++)
					{
						objWorkbook = objWorkbooks[(object)i];
						if (((_Workbook)objWorkbook).FullName.ToLower() == workBookFullName.ToLower())
						{
							i = objWorkbooks.Count + 1;
							objSheets = ((_Workbook)objWorkbook).Sheets;
							continue;
						}
						if (objWorkbook != null)
						{
							Marshal.ReleaseComObject(objWorkbook);
						}
						objWorkbook = null;
					}
					if (objWorkbook == null)
					{
						throw new ExcelException("Could not find the workbook " + workBookFullName);
					}
					return;
				}
				throw new ExcelException("No Workbooks found open");
			}
			throw new ExcelException("No Workbooks found in the application");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error selecting workbook " + workBookFullName, innerException);
		}
	}

	public static List<string> GetWorkbookNames()
	{
		List<string> list = new List<string>();
		Workbook val = null;
		try
		{
			if (objWorkbooks != null)
			{
				for (int i = 1; i <= objWorkbooks.Count; i++)
				{
					val = objWorkbooks[(object)i];
					if (val != null)
					{
						list.Add(((_Workbook)val).Name);
					}
					Marshal.ReleaseComObject(val);
					val = null;
				}
				return list;
			}
			throw new ExcelException("No workbook found open in Excel");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error retreving the list of open workbooks from excel", innerException);
		}
	}

	public static void SaveWorkBook(SaveWorkbookArguments saveWkbkArgs)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (objWorkbook != null)
			{
				((_Workbook)objWorkbook).SaveAs((object)saveWkbkArgs.Filename, saveWkbkArgs.FileFormatAsString, saveWkbkArgs.PasswordAsString, saveWkbkArgs.WriteResPasswordAsString, saveWkbkArgs.IgnoreReadOnlyRecommendedAsBoolean, saveWkbkArgs.CreateBackupAsBoolean, ExcelOptionsMapper.GetSaveAccessNode(saveWkbkArgs.AccessModeAsString), ExcelOptionsMapper.GetSaveConflictResolution(saveWkbkArgs.ConflictResolutionAsString), saveWkbkArgs.AddToMruAsBoolean, Type.Missing, Type.Missing, saveWkbkArgs.LocalAsBoolean);
				return;
			}
			throw new ExcelException("The workbook should be selected before it can be saved");
		}
		catch (Exception ex)
		{
			throw new ExcelException("Error saving the workbook, " + ex.Message, ex);
		}
	}

	public static void SaveCurrentWorkBook()
	{
		try
		{
			if (objWorkbook != null)
			{
				((_Workbook)objWorkbook).Save();
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error Saving workbook " + ((_Workbook)objWorkbook).FullName, innerException);
		}
	}

	public static void AddSheet(AddSheetArguments addSheetArgs)
	{
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Expected O, but got Unknown
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Expected O, but got Unknown
		try
		{
			List<string> sheetNames = GetSheetNames();
			if (sheetNames.Contains(addSheetArgs.SheetName))
			{
				SelectWorkSheet(addSheetArgs.SheetName);
				return;
			}
			if (objSheets != null)
			{
				Worksheet selectedWorkSheet;
				if (addSheetArgs.AfterAsString != Type.Missing)
				{
					GetWorkSheet(Convert.ToString(addSheetArgs.AfterAsString), out selectedWorkSheet);
					objWorksheet = (Worksheet)((_Workbook)objWorkbook).Sheets.Add(Type.Missing, (object)selectedWorkSheet, addSheetArgs.CountAsInteger, addSheetArgs.TypeAsString);
				}
				else
				{
					GetWorkSheet(Convert.ToString(addSheetArgs.BeforeAsString), out selectedWorkSheet);
					objWorksheet = (Worksheet)((_Workbook)objWorkbook).Sheets.Add((object)selectedWorkSheet, Type.Missing, addSheetArgs.CountAsInteger, addSheetArgs.TypeAsString);
				}
				if (selectedWorkSheet != null)
				{
					Marshal.ReleaseComObject(selectedWorkSheet);
				}
				selectedWorkSheet = null;
				if (addSheetArgs.SheetName.Length > 0)
				{
					((_Worksheet)objWorksheet).Name = addSheetArgs.SheetName;
				}
				return;
			}
			throw new ExcelException("No Worksheets collection found in the workbook");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Could not add a new worksheet", innerException);
		}
	}

	public static List<string> GetSheetNames()
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		List<string> list = new List<string>();
		try
		{
			if (objWorkbook == null)
			{
				throw new ExcelException("No Workbook selected");
			}
			if (objSheets == null)
			{
				throw new ExcelException("No Sheets found in the workbook");
			}
			for (int i = 1; i <= objSheets.Count; i++)
			{
				Worksheet val = (Worksheet)objSheets[(object)i];
				if (val != null)
				{
					list.Add(((_Worksheet)val).Name);
					Marshal.ReleaseComObject(val);
				}
				val = null;
			}
			return list;
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error retrieving Sheet Names", innerException);
		}
	}

	private static void GetWorkSheet(string workSheetName, out Worksheet selectedWorkSheet)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		try
		{
			selectedWorkSheet = null;
			if (objSheets != null)
			{
				for (int i = 1; i <= objSheets.Count; i++)
				{
					selectedWorkSheet = (Worksheet)objSheets[(object)i];
					if (selectedWorkSheet != null)
					{
						if (((_Worksheet)selectedWorkSheet).Name == workSheetName)
						{
							i = objSheets.Count + 1;
							continue;
						}
						Marshal.ReleaseComObject(selectedWorkSheet);
						selectedWorkSheet = null;
					}
				}
				if (selectedWorkSheet == null)
				{
					throw new ExcelException("Could not find worksheet " + workSheetName);
				}
				return;
			}
			throw new ExcelException("Error selecting worksheet - No Worksheets found");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error finding worksheet", innerException);
		}
	}

	public static void SelectWorkSheet(int sheetIndex)
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		try
		{
			objWorksheet = null;
			if (objSheets != null)
			{
				if (sheetIndex < 1 && sheetIndex > objSheets.Count)
				{
					throw new ExcelException("Error selecting worksheet - Invalid Sheet Index specified");
				}
				objWorksheet = (Worksheet)objSheets[(object)sheetIndex];
				if (objWorksheet != null)
				{
					((_Worksheet)objWorksheet).Activate();
				}
				return;
			}
			throw new ExcelException("Error selecting worksheet - No Worksheets found");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error selecting worksheet", innerException);
		}
	}

	public static void SelectWorkSheet(string sheetName)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		try
		{
			objWorksheet = null;
			if (objSheets != null)
			{
				for (int i = 1; i <= objSheets.Count; i++)
				{
					objWorksheet = (Worksheet)objSheets[(object)i];
					if (objWorksheet != null)
					{
						if (((_Worksheet)objWorksheet).Name == sheetName)
						{
							i = objSheets.Count + 1;
							continue;
						}
						Marshal.ReleaseComObject(objWorksheet);
						objWorksheet = null;
					}
				}
				if (objWorksheet == null)
				{
					throw new ExcelException("Could not find worksheet " + sheetName);
				}
				((_Worksheet)objWorksheet).Activate();
				return;
			}
			throw new ExcelException("Error selecting worksheet - No Worksheets found");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error selecting worksheet " + sheetName, innerException);
		}
	}

	public static void RenameSheet(string oldName, string newName)
	{
		try
		{
			SelectWorkSheet(oldName);
			SetWorkSheetName(newName);
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error renaming the sheet " + oldName, innerException);
		}
	}

	public static void SetWorkSheetName(string workSheetName)
	{
		try
		{
			if (objWorksheet == null)
			{
				throw new ExcelException("No Worksheet selected");
			}
			((_Worksheet)objWorksheet).Name = workSheetName;
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting sheet name ", innerException);
		}
	}

	public static string GetRangeInA1(int startRow, int startColumn, int endRow, int endColumn)
	{
		try
		{
			if (startRow < 1 || startColumn < 1 || endRow < 1 || endColumn < 1)
			{
				throw new ExcelException("Error getting range in A1 format - Indices cannot be less than 1");
			}
			startColumn += 64;
			endColumn += 64;
			char c = Convert.ToChar(startColumn);
			char c2 = Convert.ToChar(endColumn);
			return c + Convert.ToString(startRow) + ":" + c2 + Convert.ToString(endRow);
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error getting range in A1 format", innerException);
		}
	}

	public static void GetRangeInR1C1(string rangeInA1, out int startRow, out int startColumn, out int endRow, out int endColumn)
	{
		startRow = -1;
		startColumn = -1;
		endRow = -1;
		endColumn = -1;
		try
		{
			string[] array = rangeInA1.Split(new string[1] { ":" }, StringSplitOptions.RemoveEmptyEntries);
			if (array.Length > 0)
			{
				char[] array2 = array[0].ToCharArray();
				if (array2.Length < 2)
				{
					throw new ExcelException("Error retrieving range indices - Input in incorrect format");
				}
				startColumn = Convert.ToInt32(array2[0]);
				startColumn -= 64;
				startRow = Convert.ToInt32(array2[1]);
				startRow -= 48;
			}
			if (array.Length > 1)
			{
				char[] array3 = array[1].ToCharArray();
				if (array3.Length < 2)
				{
					throw new ExcelException("Error retrieving range indices - Input in incorrect format");
				}
				endColumn = Convert.ToInt32(array3[0]);
				endColumn -= 64;
				endRow = Convert.ToInt32(array3[1]);
				endRow -= 48;
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error retrieving range indices", innerException);
		}
	}

	public static int GetUsedRange(CellAddressType celladdresstype, out string StartCell, out string EndCell, out string errorMessage)
	{
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Expected O, but got Unknown
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Expected O, but got Unknown
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		StartCell = "";
		EndCell = "";
		errorMessage = "";
		Range val = null;
		Range val2 = null;
		Range val3 = null;
		try
		{
			if (objWorksheet == null)
			{
				errorMessage = "Error getting used range - No Worksheet selected";
				return -4019;
			}
			val = ((_Worksheet)objWorksheet).UsedRange;
			if (val != null)
			{
				val2 = (Range)val.Cells[(object)val.Row, (object)val.Column];
				val3 = (Range)val.Cells[(object)(val.Row + val.Rows.Count), (object)(val.Column + val.Columns.Count)];
				XlReferenceStyle referenceStyle = (XlReferenceStyle)1;
				MapReferenceStyle(celladdresstype, out referenceStyle);
				StartCell = val2[Type.Missing, Type.Missing, referenceStyle, Type.Missing, Type.Missing];
				EndCell = val3[Type.Missing, Type.Missing, referenceStyle, Type.Missing, Type.Missing];
				return 0;
			}
			errorMessage = "No Used Range found";
			return -4020;
		}
		catch (Exception ex)
		{
			errorMessage = "Error getting used range - " + ex.Message;
			return -4021;
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
			}
			if (val2 != null)
			{
				Marshal.ReleaseComObject(val2);
			}
			if (val3 != null)
			{
				Marshal.ReleaseComObject(val3);
			}
		}
	}

	public static void ColumnAutoFit(int columnIndex)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		Range val = null;
		try
		{
			val = (Range)((_Worksheet)objWorksheet).Cells[(object)1, (object)columnIndex];
			if (val != null)
			{
				val = val.EntireColumn;
				val.AutoFit();
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error running autofit on the column", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static void ColumnAutoFit(ExcelRange columnRange)
	{
		Range val = null;
		try
		{
			val = ((_Worksheet)objWorksheet)[((_Worksheet)objWorksheet).Cells[(object)1, (object)columnRange.StartCell.ColumnIndex], ((_Worksheet)objWorksheet).Cells[(object)1, (object)columnRange.EndCell.ColumnIndex]];
			if (val != null)
			{
				val = val.EntireColumn;
				val.AutoFit();
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error running autofit on the column", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static void ClearContents(ExcelRange range)
	{
		Range val = null;
		try
		{
			if (objWorksheet != null)
			{
				val = ((_Worksheet)objWorksheet)[((_Worksheet)objWorksheet).Cells[(object)range.StartCell.RowIndex, (object)range.StartCell.ColumnIndex], ((_Worksheet)objWorksheet).Cells[(object)range.EndCell.RowIndex, (object)range.EndCell.ColumnIndex]];
				val.Select();
				val.ClearContents();
			}
		}
		catch (Exception ex)
		{
			throw new ExcelException("ClearContents failed, " + ex);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static void SetColumnWidth(int columnIndex, double columnWidth)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		Range val = null;
		try
		{
			if (objWorksheet != null)
			{
				val = (Range)((_Worksheet)objWorksheet).Cells[(object)1, (object)columnIndex];
				val.EntireColumn.ColumnWidth = columnWidth;
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting column width", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static void SetWrapText(ExcelRange range, bool enableWordWrap)
	{
		try
		{
			SelectRange(range);
			if (objRange != null)
			{
				objRange.WrapText = enableWordWrap;
				return;
			}
			throw new ExcelException("Error wrapping text -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error wrapping text", innerException);
		}
	}

	public static double GetColumnWidth(int columnIndex)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		Range val = null;
		try
		{
			if (objWorksheet != null)
			{
				val = (Range)((_Worksheet)objWorksheet).Cells[(object)1, (object)columnIndex];
				return Convert.ToDouble(val.EntireColumn.ColumnWidth);
			}
			throw new ExcelException("Error getting column width -> No Worksheet selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error getting column width", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static double GetRowHeight(int rowIndex)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		Range val = null;
		try
		{
			if (objWorksheet != null)
			{
				val = (Range)((_Worksheet)objWorksheet).Cells[(object)rowIndex, (object)1];
				return Convert.ToDouble(val.EntireRow.RowHeight);
			}
			throw new ExcelException("Error getting row height -> No Worksheet selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error getting row height", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static double GetRangeWidth(ExcelRange range)
	{
		try
		{
			SelectRange(range);
			if (objRange != null)
			{
				return (double)objRange.Width;
			}
			throw new ExcelException("Error getting range width -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error getting range width", innerException);
		}
	}

	public static double GetRangeHeight(ExcelRange range)
	{
		try
		{
			SelectRange(range);
			if (objRange != null)
			{
				return (double)objRange.Height;
			}
			throw new ExcelException("Error getting range height -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error getting range height", innerException);
		}
	}

	public static void SetRowHeight(int rowIndex, double rowHeight)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		Range val = null;
		try
		{
			if (objWorksheet != null)
			{
				val = (Range)((_Worksheet)objWorksheet).Cells[(object)rowIndex, (object)1];
				val.EntireRow.RowHeight = rowHeight;
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting row height", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static void SetRangeBorderProperties(int rangeBorderIndex, ExcelRangeBorderProperties borderProperties)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (objRange != null)
			{
				XlBordersIndex bordersIndex = ExcelOptionsMapper.GetBordersIndex(rangeBorderIndex);
				XlLineStyle lineStyle = ExcelOptionsMapper.GetLineStyle(borderProperties.LineStyle);
				objRange.Borders[bordersIndex].LineStyle = lineStyle;
				return;
			}
			throw new ExcelException("Error Setting Range Border Properties -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting range border properties", innerException);
		}
	}

	public static void CreateNamedTable(string tableName, string rangeInR1C1)
	{
		try
		{
			if (objWorkbook != null)
			{
				Name val = ((_Workbook)objWorkbook).Names.Add((object)tableName, Type.Missing, (object)true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, (object)rangeInR1C1, Type.Missing);
				if (val != null)
				{
					Marshal.ReleaseComObject(val);
				}
				((_Workbook)objWorkbook).Save();
				return;
			}
			throw new ExcelException("Error Creating Named Table - No workbook selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error creating named table " + tableName, innerException);
		}
	}

	public static void InsertTable(DataTable dataTable, string namedTable)
	{
		int i = -1;
		try
		{
			OleDbConnection oleDbConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ((_Workbook)objWorkbook).FullName + ";Extended Properties=\"Excel 8.0;HDR=NO\"");
			OleDbCommand oleDbCommand = new OleDbCommand();
			oleDbCommand.Connection = oleDbConnection;
			string text = "Insert into [" + namedTable + "] ";
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(" values (");
			text += stringBuilder.ToString();
			oleDbConnection.Open();
			for (i = 0; i < dataTable.Rows.Count; i++)
			{
				DataRow dataRow = dataTable.Rows[i];
				StringBuilder stringBuilder2 = new StringBuilder();
				foreach (DataColumn column in dataTable.Columns)
				{
					if (!(dataRow[column] is DBNull))
					{
						string value = Convert.ToString(dataRow[column]);
						if (column.DataType != typeof(double))
						{
							stringBuilder2.Append("'");
							stringBuilder2.Append(value);
							stringBuilder2.Append("'");
						}
						else
						{
							stringBuilder2.Append(value);
						}
					}
					else
					{
						stringBuilder2.Append("null");
					}
					stringBuilder2.Append(",");
				}
				stringBuilder2.Replace(",", ")", stringBuilder2.Length - 1, 1);
				string commandText = text + stringBuilder2.ToString();
				oleDbCommand.CommandText = commandText;
				oleDbCommand.ExecuteNonQuery();
			}
			oleDbConnection.Close();
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error inserting table, RowCount = " + Convert.ToString(i), innerException);
		}
	}

	public static void InsertTwoDimensionalArray(object[,] twoDimensionalArray, ExcelCell startCell)
	{
		try
		{
			ExcelRange excelRange = new ExcelRange(startCell, new ExcelCell(startCell.RowIndex + twoDimensionalArray.GetLength(0) - 1, startCell.ColumnIndex + twoDimensionalArray.GetLength(1) - 1));
			SelectRange(excelRange);
			objRange.Value2 = twoDimensionalArray;
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error importing Xml", innerException);
		}
	}

	public static void InsertDataTableUsingArray(DataTable dataTable, ExcelCell startCell)
	{
		object[,] twoDimensionalArray = ConvertDataTableToArray(dataTable);
		InsertTwoDimensionalArray(twoDimensionalArray, startCell);
	}

	public static object[,] ConvertDataTableToArray(DataTable dataTable)
	{
		object[,] array = new object[dataTable.Rows.Count + 1, dataTable.Columns.Count];
		for (int i = 0; i < dataTable.Columns.Count; i++)
		{
			array[0, i] = dataTable.Columns[i].ColumnName;
		}
		for (int j = 0; j < dataTable.Rows.Count; j++)
		{
			for (int k = 0; k < dataTable.Columns.Count; k++)
			{
				array[j + 1, k] = dataTable.Rows[j][k];
			}
		}
		return array;
	}

	public static void InsertDataTable(DataTable dataTable, ExcelCell startCell)
	{
		InsertDataTable(dataTable, startCell, addDummyRow: false);
	}

	public static void InsertDataTable(DataTable dataTable, ExcelCell startCell, bool addDummyRow)
	{
		try
		{
			string xmlMapName = "XMLMap" + ((_Worksheet)objWorksheet).Name + dataTable.TableName;
			DataRow dataRow = null;
			if (addDummyRow)
			{
				dataRow = dataTable.NewRow();
				foreach (DataColumn column in dataTable.Columns)
				{
					if (column.DataType != typeof(byte))
					{
						dataRow[column] = -9999;
					}
				}
				dataTable.Rows.InsertAt(dataRow, 0);
			}
			StringBuilder stringBuilder = new StringBuilder();
			XmlWriter writer = XmlWriter.Create(stringBuilder);
			dataTable.WriteXml(writer);
			ImportXml(stringBuilder.ToString(), startCell, xmlMapName);
			if (dataRow != null)
			{
				dataTable.Rows.Remove(dataRow);
				ExcelCell excelCell = startCell.Copy();
				excelCell.RowIndex++;
				DeleteEntireRow(excelCell.RowIndex, shiftRows: true);
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error insert data table", innerException);
		}
	}

	public static int FindFirstCellWithValue(string value, CellAddressType celladdresstype, FindOption findOption, out string celladdress, out string errorMessage)
	{
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Expected O, but got Unknown
		celladdress = "";
		errorMessage = "";
		Range val = null;
		Range val2 = null;
		bool flag = false;
		try
		{
			if (objWorksheet == null)
			{
				errorMessage = "Error finding the cell value - No Worksheet selected";
				return -4022;
			}
			val = ((_Worksheet)objWorksheet).UsedRange;
			if (val == null)
			{
				errorMessage = "Error finding the cell value - No Used Range found";
				return -4023;
			}
			val2 = ((findOption != FindOption.Part) ? val.Find((object)value, Type.Missing, Type.Missing, (object)(XlLookAt)1, (object)(XlSearchOrder)1, (XlSearchDirection)2, (object)false, (object)false, Type.Missing) : val.Find((object)value, Type.Missing, Type.Missing, (object)(XlLookAt)2, (object)(XlSearchOrder)1, (XlSearchDirection)2, (object)false, (object)false, Type.Missing));
			if (val2 == null)
			{
				for (int i = val.Row; i <= val.Row + val.Rows.Count; i++)
				{
					for (int j = val.Column; j <= val.Column + val.Columns.Count; j++)
					{
						val2 = (Range)((_Worksheet)objWorksheet).Cells[(object)i, (object)j];
						if (val2 != null && val2.Value2 != null && val2.Value2.ToString().Trim().Contains(value))
						{
							i = val.Row + val.Rows.Count + 1;
							j = val.Column + val.Columns.Count + 1;
							flag = true;
						}
					}
				}
			}
			else
			{
				flag = true;
			}
			if (flag)
			{
				XlReferenceStyle referenceStyle = (XlReferenceStyle)1;
				MapReferenceStyle(celladdresstype, out referenceStyle);
				celladdress = val2[Type.Missing, Type.Missing, referenceStyle, Type.Missing, Type.Missing];
			}
			else
			{
				celladdress = "";
			}
			return 0;
		}
		catch (Exception ex)
		{
			errorMessage = "Error getting used range - " + ex.Message;
			return -4024;
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
			}
			if (val2 != null)
			{
				Marshal.ReleaseComObject(val2);
			}
		}
	}

	public static int FindFirstCellWithValue(string value, CellAddressType celladdresstype, out string celladdress, out string errorMessage)
	{
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Expected O, but got Unknown
		celladdress = "";
		errorMessage = "";
		Range val = null;
		Range val2 = null;
		bool flag = false;
		try
		{
			if (objWorksheet == null)
			{
				errorMessage = "Error finding the cell value - No Worksheet selected";
				return -4022;
			}
			val = ((_Worksheet)objWorksheet).UsedRange;
			if (val != null)
			{
				val2 = val.Find((object)value, Type.Missing, Type.Missing, (object)(XlLookAt)2, (object)(XlSearchOrder)1, (XlSearchDirection)2, (object)false, (object)false, Type.Missing);
				if (val2 == null)
				{
					for (int i = val.Row; i <= val.Row + val.Rows.Count; i++)
					{
						for (int j = val.Column; j <= val.Column + val.Columns.Count; j++)
						{
							val2 = (Range)((_Worksheet)objWorksheet).Cells[(object)i, (object)j];
							if (val2 != null && val2.Value2 != null && val2.Value2.ToString().Trim().Contains(value))
							{
								i = val.Row + val.Rows.Count + 1;
								j = val.Column + val.Columns.Count + 1;
								flag = true;
							}
						}
					}
				}
				else
				{
					flag = true;
				}
				if (flag)
				{
					XlReferenceStyle referenceStyle = (XlReferenceStyle)1;
					MapReferenceStyle(celladdresstype, out referenceStyle);
					celladdress = val2[Type.Missing, Type.Missing, referenceStyle, Type.Missing, Type.Missing];
				}
				else
				{
					celladdress = "";
				}
				return 0;
			}
			errorMessage = "Error finding the cell value - No Used Range found";
			return -4023;
		}
		catch (Exception ex)
		{
			errorMessage = "Error getting used range - " + ex.Message;
			return -4024;
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
			}
			if (val2 != null)
			{
				Marshal.ReleaseComObject(val2);
			}
		}
	}

	public static int GetCellContent(string cellAddress, bool cellText, out string cellContent, out string errorMessage)
	{
		errorMessage = "";
		cellContent = "";
		try
		{
			if (objWorksheet != null)
			{
				objWorkingRange1 = ((_Worksheet)objWorksheet)[(object)cellAddress, Type.Missing];
				if (cellText)
				{
					cellContent = Convert.ToString(objWorkingRange1.Text);
				}
				else
				{
					cellContent = Convert.ToString(objWorkingRange1.Value2);
				}
				return 0;
			}
			errorMessage = "No Worksheet selected. Please select a worksheet first";
			return -4027;
		}
		catch (Exception ex)
		{
			errorMessage = "Error retrieving content of the cell " + cellAddress + ": " + ex.Message;
			return -4026;
		}
	}

	public static int GetCellContent(string cellAddress, CellValue cellValue, out string cellContent, out string errorMessage)
	{
		errorMessage = "";
		cellContent = "";
		try
		{
			if (objWorksheet != null)
			{
				objWorkingRange1 = ((_Worksheet)objWorksheet)[(object)cellAddress, Type.Missing];
				switch (cellValue)
				{
				case CellValue.Formula:
					cellContent = Convert.ToString(objWorkingRange1.Formula);
					break;
				case CellValue.Value2:
					cellContent = Convert.ToString(objWorkingRange1.Value2);
					break;
				default:
					cellContent = Convert.ToString(objWorkingRange1.Text);
					break;
				}
				return 0;
			}
			errorMessage = "No Worksheet selected. Please select a worksheet first";
			return -4027;
		}
		catch (Exception ex)
		{
			errorMessage = "Error retrieving content of the cell " + cellAddress + ": " + ex.Message;
			return -4026;
		}
	}

	public static void AddImage(string filename, ExcelCell imageCell)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		Range val = null;
		try
		{
			val = (Range)((_Worksheet)objWorksheet).Cells[(object)imageCell.RowIndex, (object)imageCell.ColumnIndex];
			Image data = Image.FromFile(filename);
			Clipboard.SetDataObject(data, copy: true);
			((_Worksheet)objWorksheet).Paste((object)val, (object)filename);
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error adding the image", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static void AddImage(Image oImage, ExcelCell imageCell)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		Range val = null;
		try
		{
			val = (Range)((_Worksheet)objWorksheet).Cells[(object)imageCell.RowIndex, (object)imageCell.ColumnIndex];
			Clipboard.SetDataObject(oImage, copy: true);
			((_Worksheet)objWorksheet).Paste((object)val, Type.Missing);
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error adding the image", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static void AddHyperLink(ExcelCell hyperLinkCell, string hyperLinkText, string hyperLinkAddress, string hyperLinkSubAddress)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		try
		{
			Range val = (Range)((_Worksheet)objWorksheet).Cells[(object)hyperLinkCell.RowIndex, (object)hyperLinkCell.ColumnIndex];
			val.Hyperlinks.Add((object)val, hyperLinkAddress, (object)hyperLinkSubAddress, Type.Missing, (object)hyperLinkText);
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error adding hyperlink", innerException);
		}
	}

	public static void SetRangeAttributes(ExcelRange excelRange, ExcelRangeAttributes excelRangeAttributes)
	{
		try
		{
			SelectRange(excelRange);
			SetRangeAttributes(excelRangeAttributes);
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting range attributes", innerException);
		}
	}

	public static void SetRangeHorizontalAlignment(ExcelRange range, string alignment)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			SelectRange(range);
			if (objRange != null)
			{
				objRange.HorizontalAlignment = ExcelOptionsMapper.GetHorizontalAlignment(alignment);
				return;
			}
			throw new ExcelException("Error Setting Horizontal alignment -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting horizontal alignment", innerException);
		}
	}

	public static void SetRangeVerticalAlignment(ExcelRange range, string alignment)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			SelectRange(range);
			if (objRange != null)
			{
				objRange.VerticalAlignment = ExcelOptionsMapper.GetVerticalAlignment(alignment);
				return;
			}
			throw new ExcelException("Error Setting vertical alignment -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting vertical alignment", innerException);
		}
	}

	public static void SetRangeBackcolor(ExcelRange range, Color color)
	{
		try
		{
			SelectRange(range);
			if (objRange != null)
			{
				objRange.Interior.Color = color.ToArgb();
				return;
			}
			throw new ExcelException("Error Setting backcolor -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting backcolor", innerException);
		}
	}

	public static void SetRangeFontColor(ExcelRange range, Color color)
	{
		try
		{
			SelectRange(range);
			if (objRange != null)
			{
				objRange.Font.Color = ColorTranslator.ToOle(color);
				return;
			}
			throw new ExcelException("Error Setting font color -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting font color", innerException);
		}
	}

	public static void SetRangeFontBold(ExcelRange range, bool enableBold)
	{
		try
		{
			SelectRange(range);
			if (objRange != null)
			{
				objRange.Font.Bold = enableBold;
				return;
			}
			throw new ExcelException("Error Setting font bold -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting font bold", innerException);
		}
	}

	public static void SetRangeFontItalic(ExcelRange range, bool enableItalic)
	{
		try
		{
			SelectRange(range);
			if (objRange != null)
			{
				objRange.Font.Italic = enableItalic;
				return;
			}
			throw new ExcelException("Error Setting font italic -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting font italic", innerException);
		}
	}

	public static void SetRangeFontUnderline(ExcelRange range, bool enableUnderline)
	{
		try
		{
			SelectRange(range);
			if (objRange != null)
			{
				objRange.Font.Underline = enableUnderline;
				return;
			}
			throw new ExcelException("Error Setting font underline -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting font underline", innerException);
		}
	}

	public static void SetCellCharacterBold(ExcelCell cell, int startIndex, int length, bool enableBold)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		Characters val = null;
		try
		{
			if (objWorksheet != null)
			{
				objRange = (Range)((_Worksheet)objWorksheet).Cells[(object)cell.RowIndex, (object)cell.ColumnIndex];
				if (objRange != null)
				{
					val = objRange[(object)startIndex, (object)length];
					val.Font.Bold = enableBold;
					return;
				}
				throw new ExcelException("Error Setting font bold -> No Range selected");
			}
			throw new ExcelException("Error Setting font bold -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting font bold", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static void SetCellCharacterUnderline(ExcelCell cell, int startIndex, int length, bool enableUnderline)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		Characters val = null;
		try
		{
			if (objWorksheet != null)
			{
				objRange = (Range)((_Worksheet)objWorksheet).Cells[(object)cell.RowIndex, (object)cell.ColumnIndex];
				if (objRange != null)
				{
					val = objRange[(object)startIndex, (object)length];
					val.Font.Underline = enableUnderline;
					return;
				}
				throw new ExcelException("Error Setting font underline -> No Range selected");
			}
			throw new ExcelException("Error Setting font underline -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting font underline", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static void SetCellCharacterItalic(ExcelCell cell, int startIndex, int length, bool enableItalic)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		Characters val = null;
		try
		{
			if (objWorksheet != null)
			{
				objRange = (Range)((_Worksheet)objWorksheet).Cells[(object)cell.RowIndex, (object)cell.ColumnIndex];
				if (objRange != null)
				{
					val = objRange[(object)startIndex, (object)length];
					val.Font.Italic = enableItalic;
					return;
				}
				throw new ExcelException("Error Setting font italic -> No Range selected");
			}
			throw new ExcelException("Error Setting font italic -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting font italic", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static void SetRangeAttributes(ExcelRangeAttributes excelRangeAttributes)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (objRange != null)
			{
				objRange.AddIndent = excelRangeAttributes.AddIndent;
				objRange.HorizontalAlignment = ExcelOptionsMapper.GetHorizontalAlignment(excelRangeAttributes.HorizontalAlignment);
				objRange.IndentLevel = excelRangeAttributes.IndentLevel;
				objRange.MergeCells = excelRangeAttributes.MergeCells;
				objRange.Orientation = excelRangeAttributes.Orientation;
				objRange.ReadingOrder = excelRangeAttributes.ReadingOrder;
				objRange.ShrinkToFit = excelRangeAttributes.ShrinkToFit;
				objRange.VerticalAlignment = ExcelOptionsMapper.GetVerticalAlignment(excelRangeAttributes.VerticalAlignment);
				objRange.WrapText = excelRangeAttributes.WrapText;
				return;
			}
			throw new ExcelException("Error Setting range attributes -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting range attributes", innerException);
		}
	}

	public static void SetRangeInteriorProperties(ExcelRangeInteriorProperties interiorProperties)
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (objRange != null)
			{
				objRange.Interior.ColorIndex = ExcelOptionsMapper.GetColorIndex(interiorProperties.ColorIndex);
				objRange.Interior.Pattern = ExcelOptionsMapper.GetPattern(interiorProperties.Pattern);
				objRange.Interior.PatternColorIndex = ExcelOptionsMapper.GetColorIndex(interiorProperties.PatternColorIndex);
				return;
			}
			throw new ExcelException("Error Setting range interior properties -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting range interior properties", innerException);
		}
	}

	public static void SetRangeFontProperties(ExcelRangeFontProperties excelRangeFontProperties)
	{
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (objRange != null)
			{
				objRange.Font.ColorIndex = excelRangeFontProperties.ColorIndex;
				objRange.Font.FontStyle = excelRangeFontProperties.FontStyle;
				objRange.Font.Name = excelRangeFontProperties.Name;
				objRange.Font.OutlineFont = excelRangeFontProperties.OutlineFont;
				objRange.Font.Shadow = excelRangeFontProperties.Shadow;
				objRange.Font.Size = excelRangeFontProperties.Size;
				objRange.Font.Strikethrough = excelRangeFontProperties.Strikethrough;
				objRange.Font.Subscript = excelRangeFontProperties.Subscript;
				objRange.Font.Superscript = excelRangeFontProperties.Superscript;
				objRange.Font.Underline = ExcelOptionsMapper.GetUnderLineStyle(excelRangeFontProperties.Underline);
				return;
			}
			throw new ExcelException("Error setting range font properties -> No Range selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting range attributes", innerException);
		}
	}

	public static void SelectRangeSelect(ExcelRange excelRange)
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Expected O, but got Unknown
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Expected O, but got Unknown
		Range val = null;
		Range val2 = null;
		try
		{
			if (excelRange.StartCell.IsValid() && excelRange.EndCell.IsValid())
			{
				val = (Range)((_Worksheet)objWorksheet).Cells[(object)excelRange.StartCell.RowIndex, (object)excelRange.StartCell.ColumnIndex];
				val2 = (Range)((_Worksheet)objWorksheet).Cells[(object)excelRange.EndCell.RowIndex, (object)excelRange.EndCell.ColumnIndex];
				objRange = ((_Worksheet)objWorksheet)[(object)val, (object)val2];
			}
			else
			{
				objRange = null;
			}
			if (objRange != null)
			{
				objRange.Select();
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error selecting the range", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
			if (val2 != null)
			{
				Marshal.ReleaseComObject(val2);
				val2 = null;
			}
			if (objRange != null)
			{
				Marshal.ReleaseComObject(objRange);
				objRange = null;
			}
		}
	}

	public static void SelectRange(ExcelRange excelRange)
	{
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Expected O, but got Unknown
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Expected O, but got Unknown
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Expected O, but got Unknown
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Expected O, but got Unknown
		Range val = null;
		Range val2 = null;
		try
		{
			if (excelRange.StartCell.IsValid() && excelRange.EndCell.IsValid())
			{
				val = (Range)((_Worksheet)objWorksheet).Cells[(object)excelRange.StartCell.RowIndex, (object)excelRange.StartCell.ColumnIndex];
				val2 = (Range)((_Worksheet)objWorksheet).Cells[(object)excelRange.EndCell.RowIndex, (object)excelRange.EndCell.ColumnIndex];
				objRange = ((_Worksheet)objWorksheet)[(object)val, (object)val2];
			}
			else if (excelRange.StartCell.IsValid())
			{
				objRange = (Range)((_Worksheet)objWorksheet).Cells[(object)excelRange.StartCell.RowIndex, (object)excelRange.StartCell.ColumnIndex];
			}
			else if (excelRange.EndCell.IsValid())
			{
				objRange = (Range)((_Worksheet)objWorksheet).Cells[(object)excelRange.EndCell.RowIndex, (object)excelRange.EndCell.ColumnIndex];
			}
			else
			{
				objRange = null;
			}
			if (objRange != null)
			{
				if (excelRange.SelectEntireRow)
				{
					objRange = objRange.EntireRow;
				}
				if (excelRange.SelectEntireColumn)
				{
					objRange = objRange.EntireColumn;
				}
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error selecting the range", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
			if (val2 != null)
			{
				Marshal.ReleaseComObject(val2);
				val2 = null;
			}
		}
	}

	public static void SelectRangeAndInsert(ExcelRange excelRange)
	{
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Expected O, but got Unknown
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Expected O, but got Unknown
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Expected O, but got Unknown
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Expected O, but got Unknown
		Range val = null;
		Range val2 = null;
		try
		{
			if (excelRange.StartCell.IsValid() && excelRange.EndCell.IsValid())
			{
				val = (Range)((_Worksheet)objWorksheet).Cells[(object)excelRange.StartCell.RowIndex, (object)excelRange.StartCell.ColumnIndex];
				val2 = (Range)((_Worksheet)objWorksheet).Cells[(object)excelRange.EndCell.RowIndex, (object)excelRange.EndCell.ColumnIndex];
				objRange = ((_Worksheet)objWorksheet)[(object)val, (object)val2];
			}
			else if (excelRange.StartCell.IsValid())
			{
				objRange = (Range)((_Worksheet)objWorksheet).Cells[(object)excelRange.StartCell.RowIndex, (object)excelRange.StartCell.ColumnIndex];
			}
			else if (excelRange.EndCell.IsValid())
			{
				objRange = (Range)((_Worksheet)objWorksheet).Cells[(object)excelRange.EndCell.RowIndex, (object)excelRange.EndCell.ColumnIndex];
			}
			else
			{
				objRange = null;
			}
			if (objRange != null)
			{
				if (excelRange.SelectEntireRow)
				{
					objRange = objRange.EntireRow;
				}
				if (excelRange.SelectEntireColumn)
				{
					objRange = objRange.EntireColumn;
				}
				objRange.Insert((object)(XlInsertShiftDirection)(-4121), (object)(XlInsertFormatOrigin)0);
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error selecting the range", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
			if (val2 != null)
			{
				Marshal.ReleaseComObject(val2);
				val2 = null;
			}
		}
	}

	public static void SetCellValue(ExcelCell cell, string cellValue)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		try
		{
			if (objWorksheet != null)
			{
				Range val = (Range)((_Worksheet)objWorksheet).Cells[(object)cell.RowIndex, (object)cell.ColumnIndex];
				val.Value2 = cellValue;
				return;
			}
			throw new ExcelException("Error setting cell value - No Worksheet selected");
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting cell value", innerException);
		}
	}

	public static void MergeCells(ExcelCell startCell, ExcelCell endCell, bool mergeAcrossEachRow)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Expected O, but got Unknown
		Range val = null;
		Range val2 = null;
		Range val3 = null;
		try
		{
			val = (Range)((_Worksheet)objWorksheet).Cells[(object)startCell.RowIndex, (object)startCell.ColumnIndex];
			val2 = (Range)((_Worksheet)objWorksheet).Cells[(object)endCell.RowIndex, (object)endCell.ColumnIndex];
			val3 = ((_Worksheet)objWorksheet)[(object)val, (object)val2];
			val3.Merge((object)mergeAcrossEachRow);
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error merging cells", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val3);
				val = null;
			}
			if (val2 != null)
			{
				Marshal.ReleaseComObject(val2);
				val2 = null;
			}
			if (val3 != null)
			{
				Marshal.ReleaseComObject(val3);
				val3 = null;
			}
		}
	}

	public static void DeleteEntireRow(int rowIndex, bool shiftRows)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		try
		{
			Range val = (Range)((_Worksheet)objWorksheet).Cells[(object)rowIndex, (object)1];
			val.EntireRow.Delete((object)shiftRows);
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error deleting entire row " + Convert.ToString(rowIndex), innerException);
		}
	}

	public static void DeleteEntireColumn(int columnIndex, bool shiftColumns)
	{
		try
		{
			object obj = ((_Worksheet)objWorksheet).Cells[(object)1, (object)columnIndex];
			Range val = (Range)((obj is Range) ? obj : null);
			val.EntireColumn.Delete((object)shiftColumns);
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error deleting entire column " + Convert.ToString(columnIndex), innerException);
		}
	}

	public static void CutColumnContents(int currentColumnIndex, int newColumnIndex)
	{
		try
		{
			object obj = ((_Worksheet)objWorksheet).Cells[(object)1, (object)currentColumnIndex];
			Range val = (Range)((obj is Range) ? obj : null);
			object obj2 = ((_Worksheet)objWorksheet).Cells[(object)1, (object)newColumnIndex];
			Range val2 = (Range)((obj2 is Range) ? obj2 : null);
			val.EntireColumn.Cut((object)val2);
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error copying column " + Convert.ToString(currentColumnIndex), innerException);
		}
	}

	public static void ImportXml(string xmlData, ExcelCell startCell, string xmlMapName)
	{
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Expected O, but got Unknown
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			xmlMapName = xmlMapName.Replace(" ", "");
			xmlMapName = xmlMapName.Replace("(", "_");
			xmlMapName = xmlMapName.Replace(")", "_");
			xmlMapName = xmlMapName.Replace("|", "_");
			Range val;
			try
			{
				val = (Range)((_Worksheet)objWorksheet).Cells[(object)startCell.RowIndex, (object)startCell.ColumnIndex];
			}
			catch (Exception innerException)
			{
				throw new ExcelException("Error importing Xml -> Error selecting the ranger", innerException);
			}
			XmlMap val2 = default(XmlMap);
			try
			{
				((_Workbook)objWorkbook).XmlImportXml(xmlData, ref val2, (object)false, (object)val);
			}
			catch (Exception innerException2)
			{
				throw new ExcelException("Error importing Xml -> Error thrown by XmlImportXml", innerException2);
			}
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
			if (val2 != null)
			{
				try
				{
					val2.Name = xmlMapName;
				}
				catch (Exception innerException3)
				{
					throw new ExcelException("Error importing Xml -> Error renaming the xml map", innerException3);
				}
				Marshal.ReleaseComObject(val2);
				val2 = null;
			}
		}
		catch (Exception innerException4)
		{
			throw new ExcelException("Error importing Xml", innerException4);
		}
	}

	public static void AddChartObject(ExcelRange fillRange, string chartObjectName)
	{
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		ChartObject val = null;
		Range val2 = null;
		val2 = ((_Worksheet)objWorksheet)[((_Worksheet)objWorksheet).Cells[(object)fillRange.StartCell.RowIndex, (object)fillRange.StartCell.ColumnIndex], ((_Worksheet)objWorksheet).Cells[(object)fillRange.EndCell.RowIndex, (object)fillRange.EndCell.ColumnIndex]];
		double num = (double)val2.Top;
		double num2 = (double)val2.Left;
		double num3 = (double)val2.Height;
		double num4 = (double)val2.Width;
		val = ((ChartObjects)((_Worksheet)objWorksheet).ChartObjects(Type.Missing)).Add(num2, num, num4, num3);
		val.Name = chartObjectName;
		objChart = val.Chart;
	}

	public static void SetCurrentChartType(string ChartType)
	{
		if (objChart != null && ChartType == ((object)(XlChartType)74).ToString())
		{
			((_Chart)objChart).ChartType = (XlChartType)74;
		}
	}

	public static void SetCurrentChartTitle(string chartTitle)
	{
		if (objChart != null)
		{
			((_Chart)objChart).ChartTitle.Text = chartTitle;
		}
	}

	public static void SelectEmbeddedChart(string chartObjectName)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		ChartObjects val = null;
		ChartObject val2 = null;
		try
		{
			val = (ChartObjects)((_Worksheet)objWorksheet).ChartObjects(Type.Missing);
			for (int i = 1; i <= val.Count; i++)
			{
				val2 = (ChartObject)val.Item((object)i);
				if (val2.Name == chartObjectName)
				{
					objChart = val2.Chart;
					i = val.Count + 1;
				}
				else
				{
					val2 = null;
				}
			}
			if (val2 == null)
			{
				throw new ExcelException("Error selecting the embedded chart -> No chart object found with the name " + chartObjectName);
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error selecting the embedded chart", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
			if (val2 != null)
			{
				Marshal.ReleaseComObject(val2);
				val2 = null;
			}
		}
	}

	public static void AddChart(AddChartArguments addChartArguments)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		try
		{
			if (objWorkbook != null)
			{
				objChart = (Chart)((_Workbook)objWorkbook).Charts.Add(addChartArguments.BeforeAsString, addChartArguments.AfterAsString, addChartArguments.CountAsInteger, addChartArguments.TypeAsString);
				((_Chart)objChart).Name = addChartArguments.ChartName;
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error adding a chart to the current workbook", innerException);
		}
	}

	public static void SelectChart(string chartName)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Expected O, but got Unknown
		Chart val = null;
		try
		{
			if (objWorkbook == null)
			{
				return;
			}
			for (int i = 1; i <= ((_Workbook)objWorkbook).Charts.Count; i++)
			{
				val = (Chart)((_Workbook)objWorkbook).Charts[(object)i];
				if (((_Chart)val).Name == chartName)
				{
					objChart = (Chart)((_Workbook)objWorkbook).Charts[(object)i];
					i = ((_Workbook)objWorkbook).Charts.Count + 1;
				}
				else
				{
					Marshal.ReleaseComObject(val);
					val = null;
				}
			}
			if (val == null)
			{
				throw new ExcelException("Error selecting chart -> No chart found with the name " + chartName);
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error selecting chart", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static void SetChartLocation(string chartLocation, string name)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (objChart != null)
			{
				XlChartLocation chartLocation2 = ExcelOptionsMapper.GetChartLocation(chartLocation);
				((_Chart)objChart).Location(chartLocation2, (object)name);
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting chart location", innerException);
		}
	}

	public static void ChartWizard(ChartWizardArguments chartWizardArguments)
	{
		Range val = null;
		try
		{
			if (objChart != null)
			{
				val = ((_Worksheet)objWorksheet)[((_Worksheet)objWorksheet).Cells[(object)chartWizardArguments.SourceRange.StartCell.RowIndex, (object)chartWizardArguments.SourceRange.StartCell.ColumnIndex], ((_Worksheet)objWorksheet).Cells[(object)chartWizardArguments.SourceRange.EndCell.RowIndex, (object)chartWizardArguments.SourceRange.EndCell.ColumnIndex]];
				object chartType = ExcelOptionsMapper.GetChartType(chartWizardArguments.Gallery);
				object missing = Type.Missing;
				object rowCol = ExcelOptionsMapper.GetRowCol(chartWizardArguments.PlotBy);
				object obj = chartWizardArguments.CategoryLabelsAsInteger;
				object obj2 = chartWizardArguments.SeriesLablesAsInteger;
				object obj3 = chartWizardArguments.HasLegend;
				object title = chartWizardArguments.Title;
				object categoryTitle = chartWizardArguments.CategoryTitle;
				object valueTitle = chartWizardArguments.ValueTitle;
				object extraTitle = chartWizardArguments.ExtraTitle;
				((_Chart)objChart).ChartWizard((object)val, chartType, missing, rowCol, obj, obj2, obj3, title, categoryTitle, valueTitle, extraTitle);
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error executing chart wizard", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static void SetSelectedChartLayout(int layout)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		if (objChart != null)
		{
			((_Chart)objChart).ApplyLayout(layout, (object)((_Chart)objChart).ChartType);
		}
	}

	public static void SetSelectedChartLegendPosition(string legendPosition)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		if (objChart != null)
		{
			((_Chart)objChart).Legend.Position = ExcelOptionsMapper.GetLegendPosition(legendPosition);
		}
	}

	public static void RemoveSeries(int seriesIndex)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		if (objChart != null)
		{
			SeriesCollection val = null;
			try
			{
				val = (SeriesCollection)((_Chart)objChart).SeriesCollection(Type.Missing);
				val.Item((object)seriesIndex).Delete();
			}
			catch
			{
			}
		}
	}

	public static void AddSeries(ExcelCell nameCell, ExcelRange valueRange, string seriesName)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Expected O, but got Unknown
		if (objChart != null)
		{
			SeriesCollection val = null;
			Series val2 = null;
			Range val3 = null;
			try
			{
				val = (SeriesCollection)((_Chart)objChart).SeriesCollection(Type.Missing);
				val2 = val.NewSeries();
				val3 = (Range)((_Worksheet)objWorksheet).Cells[(object)nameCell.RowIndex, (object)nameCell.ColumnIndex];
				val2.Name = seriesName;
				val3 = ((_Worksheet)objWorksheet)[((_Worksheet)objWorksheet).Cells[(object)valueRange.StartCell.RowIndex, (object)valueRange.StartCell.ColumnIndex], ((_Worksheet)objWorksheet).Cells[(object)valueRange.EndCell.RowIndex, (object)valueRange.EndCell.ColumnIndex]];
				val2.Values = val3;
			}
			catch
			{
			}
		}
	}

	public static void AddSeries(ExcelCell nameCell, ExcelRange valueRange, ExcelRange xValueRange, string seriesName)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Expected O, but got Unknown
		if (objChart != null)
		{
			SeriesCollection val = null;
			Series val2 = null;
			Range val3 = null;
			Range val4 = null;
			try
			{
				val = (SeriesCollection)((_Chart)objChart).SeriesCollection(Type.Missing);
				val2 = val.NewSeries();
				val3 = (Range)((_Worksheet)objWorksheet).Cells[(object)nameCell.RowIndex, (object)nameCell.ColumnIndex];
				val2.Name = seriesName;
				val3 = ((_Worksheet)objWorksheet)[((_Worksheet)objWorksheet).Cells[(object)valueRange.StartCell.RowIndex, (object)valueRange.StartCell.ColumnIndex], ((_Worksheet)objWorksheet).Cells[(object)valueRange.EndCell.RowIndex, (object)valueRange.EndCell.ColumnIndex]];
				val4 = ((_Worksheet)objWorksheet)[((_Worksheet)objWorksheet).Cells[(object)xValueRange.StartCell.RowIndex, (object)xValueRange.StartCell.ColumnIndex], ((_Worksheet)objWorksheet).Cells[(object)xValueRange.EndCell.RowIndex, (object)xValueRange.EndCell.ColumnIndex]];
				val2.Values = val3;
				val2.XValues = val4;
			}
			catch
			{
			}
		}
	}

	private static bool IsLegendAvailable()
	{
		try
		{
			if (((_Chart)objChart).Legend != null)
			{
				return true;
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	public static void FormatAsDataChart(List<int> displayLegendSeriesIndices, List<int> limitSeriesIndices, ChartWizardArguments chartWizardArguments)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		LegendEntries val = null;
		Series val2 = null;
		SeriesCollection val3 = null;
		Axis val4 = null;
		Axis val5 = null;
		Axis val6 = null;
		Axis val7 = null;
		if (objChart == null)
		{
			return;
		}
		try
		{
			FormatAsSummaryReportChart(chartWizardArguments);
			val3 = (SeriesCollection)((_Chart)objChart).SeriesCollection(Type.Missing);
			if (IsLegendAvailable())
			{
				val = (LegendEntries)((_Chart)objChart).Legend.LegendEntries(Type.Missing);
				List<LegendEntry> list = new List<LegendEntry>();
				if (displayLegendSeriesIndices.Count + chartWizardArguments.ShowSNWhenNoOfUnits < val.Count)
				{
					for (int i = 1; i <= val.Count; i++)
					{
						if (!displayLegendSeriesIndices.Contains(i))
						{
							list.Add(val.Item((object)i));
						}
					}
					for (int j = 0; j < list.Count; j++)
					{
						LegendEntry val8 = list[j];
						val8.Delete();
						Marshal.ReleaseComObject(val8);
						val8 = null;
					}
				}
			}
			for (int k = 1; k <= val3.Count; k++)
			{
				val2 = val3.Item((object)k);
				val2.MarkerStyle = (XlMarkerStyle)8;
				val2.Shadow = false;
				val2.AxisGroup = (XlAxisGroup)1;
				if (displayLegendSeriesIndices.Contains(k))
				{
					val2.ChartType = (XlChartType)65;
					val2.Border.Weight = (object)(XlBorderWeight)(-4138);
					val2.Smooth = true;
					if (limitSeriesIndices.Contains(k))
					{
						val2.Border.ColorIndex = 3;
						val2.MarkerBackgroundColorIndex = (XlColorIndex)3;
						val2.MarkerForegroundColorIndex = (XlColorIndex)3;
					}
				}
				else
				{
					val2.Smooth = false;
				}
				if (val2 != null)
				{
					Marshal.ReleaseComObject(val2);
					val2 = null;
				}
			}
			for (int l = 1; l <= val3.Count; l++)
			{
				val2 = val3.Item((object)l);
				val2.AxisGroup = (XlAxisGroup)1;
				if (val2 != null)
				{
					Marshal.ReleaseComObject(val2);
					val2 = null;
				}
			}
		}
		catch
		{
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
			if (val3 != null)
			{
				Marshal.ReleaseComObject(val3);
				val3 = null;
			}
			if (val2 != null)
			{
				Marshal.ReleaseComObject(val2);
				val2 = null;
			}
			if (val4 != null)
			{
				Marshal.ReleaseComObject(val4);
				val4 = null;
			}
			if (val5 != null)
			{
				Marshal.ReleaseComObject(val5);
				val5 = null;
			}
			if (val6 != null)
			{
				Marshal.ReleaseComObject(val6);
				val6 = null;
			}
			if (val7 != null)
			{
				Marshal.ReleaseComObject(val7);
				val7 = null;
			}
		}
	}

	public static void FormatAsStatsChart(ChartWizardArguments chartWizardArguments)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		SeriesCollection val = null;
		if (objChart == null)
		{
			return;
		}
		try
		{
			FormatAsSummaryReportChart(chartWizardArguments);
			val = (SeriesCollection)((_Chart)objChart).SeriesCollection(Type.Missing);
		}
		catch
		{
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	private static void FormatAsSummaryReportChart(ChartWizardArguments chartWizardArguments)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Expected O, but got Unknown
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		LegendEntries val = null;
		Axis val2 = null;
		Axis val3 = null;
		if (objChart == null)
		{
			return;
		}
		try
		{
			((_Chart)objChart).PlotArea.Interior.ColorIndex = (object)(XlColorIndex)(-4142);
			val2 = (Axis)((_Chart)objChart).Axes((object)(XlAxisType)1, (XlAxisGroup)1);
			val2.AxisBetweenCategories = true;
			val2.HasMajorGridlines = true;
			val2.MajorGridlines.Border.ColorIndex = 15;
			val2.MajorGridlines.Border.LineStyle = (object)(XlLineStyle)1;
			val2.MajorGridlines.Border.Weight = (object)(XlBorderWeight)1;
			if (!chartWizardArguments.ValueAxis.TickLabel.TickLabelSpacingIsAuto)
			{
				if (chartWizardArguments.ValueAxis.TickLabel.TickLabelSpacing < 1)
				{
					val2.TickLabelSpacing = 1;
				}
				else
				{
					val2.TickLabelSpacing = chartWizardArguments.ValueAxis.TickLabel.TickLabelSpacing;
				}
			}
			val2.TickLabels.Font.Size = 8;
			val3 = (Axis)((_Chart)objChart).Axes((object)(XlAxisType)2, (XlAxisGroup)1);
			val3.Crosses = (XlAxisCrosses)(-4114);
			val3.CrossesAt = val3.MinimumScale;
			val3.HasMajorGridlines = true;
			val3.MajorGridlines.Border.ColorIndex = 15;
			val3.MajorGridlines.Border.LineStyle = (object)(XlLineStyle)1;
			val3.MajorGridlines.Border.Weight = (object)(XlBorderWeight)1;
			if (!chartWizardArguments.CategoryAxis.MaximumScaleIsAuto)
			{
				val3.MaximumScale = chartWizardArguments.CategoryAxis.MaximumScale;
			}
			if (!chartWizardArguments.CategoryAxis.MinimumScaleIsAuto)
			{
				val3.MinimumScale = chartWizardArguments.CategoryAxis.MinimumScale;
			}
			val3.TickLabels.Font.Size = 8;
			if (IsLegendAvailable())
			{
				((_Chart)objChart).Legend.Shadow = true;
				((_Chart)objChart).Legend.Position = ExcelOptionsMapper.GetLegendPosition(chartWizardArguments.LegendPosition);
			}
		}
		catch
		{
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
			}
			if (val2 != null)
			{
				Marshal.ReleaseComObject(val2);
				val2 = null;
			}
			if (val3 != null)
			{
				Marshal.ReleaseComObject(val3);
				val3 = null;
			}
		}
	}

	public static void CopyRange(ExcelRange sourceRange, ExcelRange destinationRange)
	{
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Expected O, but got Unknown
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Expected O, but got Unknown
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Expected O, but got Unknown
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Expected O, but got Unknown
		Range val = null;
		Range val2 = null;
		Range val3 = null;
		Range val4 = null;
		Range val5 = null;
		Range val6 = null;
		string text = "";
		string text2 = "";
		try
		{
			if (objWorkbook != null)
			{
				text2 = ((_Workbook)objWorkbook).FullName;
			}
			if (objWorksheet != null)
			{
				text = ((_Worksheet)objWorksheet).Name;
			}
			if (sourceRange.StartCell.WorkbookName.Length > 0 && sourceRange.StartCell.WorksheetName.Length > 0)
			{
				SelectWorkBook(sourceRange.StartCell.WorkbookName);
				SelectWorkSheet(sourceRange.StartCell.WorksheetName);
			}
			if (objWorksheet != null)
			{
				val = (Range)((_Worksheet)objWorksheet).Cells[(object)sourceRange.StartCell.RowIndex, (object)sourceRange.StartCell.ColumnIndex];
				val2 = (Range)((_Worksheet)objWorksheet).Cells[(object)sourceRange.EndCell.RowIndex, (object)sourceRange.EndCell.ColumnIndex];
				val5 = ((_Worksheet)objWorksheet)[(object)val, (object)val2];
			}
			if (destinationRange.StartCell.WorkbookName.Length > 0 && destinationRange.StartCell.WorksheetName.Length > 0)
			{
				SelectWorkBook(destinationRange.StartCell.WorkbookName);
				SelectWorkSheet(destinationRange.StartCell.WorksheetName);
			}
			if (objWorksheet != null)
			{
				val3 = (Range)((_Worksheet)objWorksheet).Cells[(object)destinationRange.StartCell.RowIndex, (object)destinationRange.StartCell.ColumnIndex];
				val4 = (Range)((_Worksheet)objWorksheet).Cells[(object)destinationRange.EndCell.RowIndex, (object)destinationRange.EndCell.ColumnIndex];
				val6 = ((_Worksheet)objWorksheet)[(object)val3, (object)val4];
				val5.Copy((object)val6);
			}
			if (text2.Length > 0)
			{
				SelectWorkBook(text2);
			}
			if (text.Length > 0)
			{
				SelectWorkSheet(text);
			}
		}
		catch (Exception)
		{
			throw;
		}
	}

	public static void SetFormula(ExcelRange range, string formula)
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		Range val = null;
		Range val2 = null;
		try
		{
			if (objWorksheet != null)
			{
				val = (Range)((_Worksheet)objWorksheet).Cells[(object)range.StartCell.RowIndex, (object)range.StartCell.ColumnIndex];
				val.FormulaR1C1 = formula;
				if (!range.StartCell.IsSame(range.EndCell))
				{
					val2 = ((_Worksheet)objWorksheet)[((_Worksheet)objWorksheet).Cells[(object)range.StartCell.RowIndex, (object)range.StartCell.ColumnIndex], ((_Worksheet)objWorksheet).Cells[(object)range.EndCell.RowIndex, (object)range.EndCell.ColumnIndex]];
					val.AutoFill(val2, (XlAutoFillType)0);
				}
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting the formula", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
			if (val2 != null)
			{
				Marshal.ReleaseComObject(val2);
				val2 = null;
			}
		}
	}

	public static void SelectAxis(string axisType, string axisGroup)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		try
		{
			objAxis = (Axis)((_Chart)objChart).Axes((object)ExcelOptionsMapper.GetChartAxisType(axisType), ExcelOptionsMapper.GetAxisGroup(axisGroup));
		}
		catch
		{
		}
	}

	public static void SetChartTitleText(string chartTitleText)
	{
		ChartTitle val = null;
		try
		{
			if (objChart != null)
			{
				val = ((_Chart)objChart).ChartTitle;
				val.Text = chartTitleText;
			}
		}
		catch (Exception)
		{
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static Chart GetCurrentChart()
	{
		return objChart;
	}

	public static void InsertRows(ExcelCell cell, int noOfRows)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		Range val = null;
		if (objWorksheet == null)
		{
			return;
		}
		try
		{
			val = (Range)((_Worksheet)objWorksheet).Cells[(object)cell.RowIndex, (object)cell.ColumnIndex];
			while (noOfRows > 0)
			{
				val.EntireRow.Insert((object)(XlDirection)(-4121), (object)false);
				noOfRows--;
			}
		}
		catch
		{
		}
	}

	public static ExcelRange GetUsedRange()
	{
		Range val = null;
		if (objWorksheet != null)
		{
			try
			{
				val = ((_Worksheet)objWorksheet).UsedRange;
				ExcelRange excelRange = new ExcelRange();
				excelRange.StartCell = new ExcelCell(val.Row, val.Column);
				val = val.SpecialCells((XlCellType)11, Type.Missing);
				excelRange.EndCell = new ExcelCell(val.Row, val.Column);
				return excelRange;
			}
			catch (Exception innerException)
			{
				throw new ExcelException("Error getting the end cell of the current worksheet", innerException);
			}
			finally
			{
				if (val != null)
				{
					Marshal.ReleaseComObject(val);
				}
			}
		}
		throw new ExcelException("Error getting the end cell of the current worksheet - No Worksheet selected");
	}

	private static bool MapReferenceStyle(CellAddressType celladdresstype, out XlReferenceStyle referenceStyle)
	{
		bool result = false;
		referenceStyle = (XlReferenceStyle)1;
		switch (celladdresstype)
		{
		case CellAddressType.A1:
			referenceStyle = (XlReferenceStyle)1;
			result = true;
			break;
		case CellAddressType.R1C1:
			referenceStyle = (XlReferenceStyle)(-4150);
			result = true;
			break;
		}
		return result;
	}

	public static void SetExcelVisibility(bool excelVisible)
	{
		((_Application)objApplication).Visible = excelVisible;
	}

	public static void FreezePane(int rowIndex, int columnIndex)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		Range val = null;
		try
		{
			val = (Range)((_Worksheet)objWorksheet).Cells[(object)rowIndex, (object)columnIndex];
			val.Activate();
			((_Application)val.Application).ActiveWindow.SplitColumn = columnIndex;
			((_Application)val.Application).ActiveWindow.SplitRow = rowIndex;
			((_Application)val.Application).ActiveWindow.FreezePanes = true;
		}
		catch
		{
			throw;
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static void SaveWorkSheetAsCSV(string outputFileName)
	{
		if (objWorksheet != null)
		{
			((_Worksheet)objWorksheet).SaveAs(outputFileName, (object)(XlFileFormat)6, Type.Missing, Type.Missing, Type.Missing, (object)false, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
			return;
		}
		throw new ExcelException("Error Saving Workbook as csv - No Worksheet selected");
	}

	public static void FormatAsHistogramChart(ChartWizardArguments chartWizardArguments)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		if (objChart != null)
		{
			try
			{
				((_Chart)objChart).Legend.Position = ExcelOptionsMapper.GetLegendPosition(chartWizardArguments.LegendPosition);
			}
			catch
			{
			}
		}
	}

	private static string GetLocalizedFormula(string formula)
	{
		Range val = ((_Worksheet)objWorksheet)[(object)"z1", (object)Missing.Value];
		object value = val.Value2;
		val.Formula = formula;
		string result = val.FormulaLocal.ToString();
		val.Formula = "";
		val.Value2 = value;
		return result;
	}

	public static void SetConditionalFormatting(ExcelRange range, FormattingRuleType ruleType, string formula, Color fontColor, Color cellColor)
	{
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Expected O, but got Unknown
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Expected O, but got Unknown
		Range val = null;
		FormatCondition val2 = null;
		string localizedFormula = GetLocalizedFormula(formula);
		try
		{
			if (objWorksheet != null)
			{
				val = ((_Worksheet)objWorksheet)[((_Worksheet)objWorksheet).Cells[(object)range.StartCell.RowIndex, (object)range.StartCell.ColumnIndex], ((_Worksheet)objWorksheet).Cells[(object)range.EndCell.RowIndex, (object)range.EndCell.ColumnIndex]];
				val.Select();
				switch (ruleType)
				{
				case FormattingRuleType.CellValue:
					val2 = (FormatCondition)val.FormatConditions.Add((XlFormatConditionType)1, (object)(XlFormatConditionOperator)3, (object)localizedFormula, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
					break;
				case FormattingRuleType.Formula:
					val2 = (FormatCondition)val.FormatConditions.Add((XlFormatConditionType)2, (object)(XlFormatConditionOperator)3, (object)localizedFormula, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
					break;
				}
				val2.Font.Color = ColorTranslator.ToOle(fontColor);
				val2.Interior.Color = ColorTranslator.ToOle(cellColor);
				val2.Interior.PatternColorIndex = (object)(XlColorIndex)(-4105);
				val2.StopIfTrue = false;
			}
		}
		catch (Exception ex)
		{
			throw new ExcelException("Error setting the conditional formatting:\n" + ex.ToString(), ex);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
			if (val2 != null)
			{
				Marshal.ReleaseComObject(val2);
				val2 = null;
			}
		}
	}

	public static void SetConditionalFormatting(ExcelRange range, string formula, Color fontColor, Color cellColor)
	{
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Expected O, but got Unknown
		Range val = null;
		FormatCondition val2 = null;
		try
		{
			if (objWorksheet != null)
			{
				val = ((_Worksheet)objWorksheet)[((_Worksheet)objWorksheet).Cells[(object)range.StartCell.RowIndex, (object)range.StartCell.ColumnIndex], ((_Worksheet)objWorksheet).Cells[(object)range.EndCell.RowIndex, (object)range.EndCell.ColumnIndex]];
				val2 = (FormatCondition)val.FormatConditions.Add((XlFormatConditionType)1, (object)(XlFormatConditionOperator)3, (object)formula, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
				val2.Font.Color = ColorTranslator.ToOle(fontColor);
				val2.Interior.Color = ColorTranslator.ToOle(cellColor);
				val2.Interior.PatternColorIndex = (object)(XlColorIndex)(-4105);
				val2.StopIfTrue = false;
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting the conditional formatting", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
			if (val2 != null)
			{
				Marshal.ReleaseComObject(val2);
				val2 = null;
			}
		}
	}

	public static void SetConditionalFormatting_Limits(ExcelRange range, string formula, Color fontColor, Color cellColor)
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Expected O, but got Unknown
		char[] separator = new char[2] { '<', '>' };
		formula = formula.Replace(" ", "");
		string[] array = formula.Split(separator);
		if (array.Length != 2)
		{
			throw new ExcelException("Mal formed formula. Expected format: '< 2'");
		}
		XlFormatConditionOperator val = ((!formula.Contains("<")) ? ((XlFormatConditionOperator)5) : ((XlFormatConditionOperator)6));
		Range val2 = null;
		FormatCondition val3 = null;
		try
		{
			if (objWorksheet != null)
			{
				val2 = ((_Worksheet)objWorksheet)[((_Worksheet)objWorksheet).Cells[(object)range.StartCell.RowIndex, (object)range.StartCell.ColumnIndex], ((_Worksheet)objWorksheet).Cells[(object)range.EndCell.RowIndex, (object)range.EndCell.ColumnIndex]];
				val3 = (FormatCondition)val2.FormatConditions.Add((XlFormatConditionType)1, (object)val, (object)array[array.Length - 1], Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
				val3.Font.Color = ColorTranslator.ToOle(fontColor);
				val3.Interior.Color = ColorTranslator.ToOle(cellColor);
				val3.Interior.PatternColorIndex = (object)(XlColorIndex)(-4105);
				val3.StopIfTrue = false;
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting the conditional formatting", innerException);
		}
		finally
		{
			if (val2 != null)
			{
				Marshal.ReleaseComObject(val2);
				val2 = null;
			}
			if (val3 != null)
			{
				Marshal.ReleaseComObject(val3);
				val3 = null;
			}
		}
	}

	public static void SetCurrentWorksheetRangeNumberFormat(string numberFormatString)
	{
		Range val = null;
		try
		{
			if (objWorksheet != null)
			{
				val = ((_Worksheet)objWorksheet).Cells;
				val.NumberFormat = numberFormatString;
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting the NumberFormat", innerException);
		}
	}

	public static void SetColumnFormatting(int columnIndex, string numberFormatString)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		Range val = null;
		try
		{
			if (objWorksheet != null)
			{
				val = (Range)((_Worksheet)objWorksheet).Cells[(object)1, (object)columnIndex];
				val = val.EntireColumn;
				val.NumberFormat = numberFormatString;
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting the NumberFormat", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static void SetRangeNumberFormat(ExcelRange range, string numberFormatString)
	{
		Range val = null;
		try
		{
			if (objWorksheet != null)
			{
				val = ((_Worksheet)objWorksheet)[((_Worksheet)objWorksheet).Cells[(object)range.StartCell.RowIndex, (object)range.StartCell.ColumnIndex], ((_Worksheet)objWorksheet).Cells[(object)range.EndCell.RowIndex, (object)range.EndCell.ColumnIndex]];
				val.NumberFormat = numberFormatString;
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting the Number format", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	public static void ClearAutoFilter()
	{
		try
		{
			if (objWorksheet != null)
			{
				((_Worksheet)objWorksheet).AutoFilterMode = false;
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error clearing the Auto Filter", innerException);
		}
	}

	public static void SetAutoFilter(ExcelRange range)
	{
		Range val = null;
		try
		{
			if (objWorksheet != null)
			{
				val = ((_Worksheet)objWorksheet)[((_Worksheet)objWorksheet).Cells[(object)range.StartCell.RowIndex, (object)range.StartCell.ColumnIndex], ((_Worksheet)objWorksheet).Cells[(object)range.EndCell.RowIndex, (object)range.EndCell.ColumnIndex]];
				val.AutoFilter((object)1, Type.Missing, (XlAutoFilterOperator)1, Type.Missing, (object)true);
			}
		}
		catch (Exception innerException)
		{
			throw new ExcelException("Error setting the Auto Filter", innerException);
		}
		finally
		{
			if (val != null)
			{
				Marshal.ReleaseComObject(val);
				val = null;
			}
		}
	}

	private static void SetUSCulture()
	{
		originalCultureInfo = Thread.CurrentThread.CurrentCulture;
		Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
	}

	private static void ResetCulture()
	{
		Thread.CurrentThread.CurrentCulture = originalCultureInfo;
	}

	public static void RunMacro(string filename, string macroname, string[] args)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		Application val = (Application)new ApplicationClass();
		Workbook val2 = ((_Application)val).Workbooks.Open(filename, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value);
		((_Application)val).Run((object)macroname, (object)args[0], (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value, (object)Missing.Value);
		((_Workbook)val2).Close((object)false, (object)Missing.Value, (object)Missing.Value);
		((_Application)val).Quit();
		releaseObject(val);
		releaseObject(val2);
	}

	private static void releaseObject(object obj)
	{
		try
		{
			Marshal.ReleaseComObject(obj);
			obj = null;
		}
		catch (Exception)
		{
			obj = null;
		}
		finally
		{
			GC.Collect();
		}
	}
}
