764 lines
20 KiB
C#
764 lines
20 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using CPF.ReoGrid.Common;
|
|
using CPF.ReoGrid.Events;
|
|
using CPF.ReoGrid.Interaction;
|
|
using CPF.ReoGrid.IO;
|
|
using CPF.ReoGrid.Main;
|
|
using CPF.ReoGrid.Print;
|
|
|
|
namespace CPF.ReoGrid
|
|
{
|
|
internal class Workbook : IWorkbook, IDisposable, IPrintableContainer
|
|
{
|
|
public ReoGridControl ControlInstance
|
|
{
|
|
get
|
|
{
|
|
return (ReoGridControl)this.controlAdapter.ControlInstance;
|
|
}
|
|
}
|
|
|
|
public bool Readonly
|
|
{
|
|
get
|
|
{
|
|
return this.isReadonly;
|
|
}
|
|
set
|
|
{
|
|
this.isReadonly = value;
|
|
foreach (Worksheet worksheet in this.worksheets)
|
|
{
|
|
worksheet.SetSettings(WorksheetSettings.Edit_Readonly, value);
|
|
}
|
|
}
|
|
}
|
|
|
|
public Workbook(IControlAdapter adapter)
|
|
{
|
|
Stopwatch stopwatch = Stopwatch.StartNew();
|
|
Debug.WriteLine("start creating workbook...");
|
|
bool flag = adapter != null;
|
|
if (flag)
|
|
{
|
|
this.controlAdapter = adapter;
|
|
this.AttachSheetTabControl(this.controlAdapter.SheetTabControl);
|
|
}
|
|
stopwatch.Stop();
|
|
Debug.WriteLine("creating workbook done: " + stopwatch.ElapsedMilliseconds.ToString() + " ms.");
|
|
}
|
|
|
|
static Workbook()
|
|
{
|
|
Workbook.FileFormatProviders[FileFormat.ReoGridFormat] = new ReoGridFileFormatProvider();
|
|
Workbook.FileFormatProviders[FileFormat.Excel2007] = new ExcelFileFormatProvider();
|
|
Workbook.FileFormatProviders[FileFormat.CSV] = new CSVFileFormatProvider();
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
this.ClearWorksheets();
|
|
}
|
|
|
|
public void Save(string path)
|
|
{
|
|
this.Save(path, FileFormat._Auto);
|
|
}
|
|
|
|
public void Save(string path, FileFormat fileFormat)
|
|
{
|
|
this.Save(path, fileFormat, Encoding.Default);
|
|
}
|
|
|
|
public void Save(string path, FileFormat fileFormat, Encoding encoding)
|
|
{
|
|
bool flag = fileFormat == FileFormat._Auto;
|
|
if (flag)
|
|
{
|
|
foreach (KeyValuePair<FileFormat, IFileFormatProvider> keyValuePair in Workbook.FileFormatProviders)
|
|
{
|
|
bool flag2 = keyValuePair.Value.IsValidFormat(path);
|
|
if (flag2)
|
|
{
|
|
fileFormat = keyValuePair.Key;
|
|
break;
|
|
}
|
|
}
|
|
bool flag3 = fileFormat == FileFormat._Auto;
|
|
if (flag3)
|
|
{
|
|
throw new NotSupportedException("Cannot determine a file format to load workbook from specified path, try specify the file format.");
|
|
}
|
|
}
|
|
using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
|
|
{
|
|
this.Save(fileStream, fileFormat, encoding);
|
|
}
|
|
}
|
|
|
|
public void Save(Stream stream, FileFormat fileFormat)
|
|
{
|
|
this.Save(stream, fileFormat, Encoding.Default);
|
|
}
|
|
|
|
public void Save(Stream stream, FileFormat fileFormat, Encoding encoding)
|
|
{
|
|
IFileFormatProvider fileFormatProvider;
|
|
bool flag = !Workbook.FileFormatProviders.TryGetValue(fileFormat, out fileFormatProvider);
|
|
if (flag)
|
|
{
|
|
throw new FileFormatNotSupportException("Specified file format is not supported");
|
|
}
|
|
bool flag2 = this.controlAdapter != null;
|
|
if (flag2)
|
|
{
|
|
this.controlAdapter.ChangeCursor(CursorStyle.Busy);
|
|
}
|
|
try
|
|
{
|
|
fileFormatProvider.Save(this, stream, encoding, null);
|
|
}
|
|
finally
|
|
{
|
|
bool flag3 = this.controlAdapter != null;
|
|
if (flag3)
|
|
{
|
|
this.controlAdapter.ChangeCursor(CursorStyle.PlatformDefault);
|
|
}
|
|
bool flag4 = this.WorkbookSaved != null;
|
|
if (flag4)
|
|
{
|
|
this.WorkbookSaved(this, null);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Load(string path)
|
|
{
|
|
this.Load(path, FileFormat._Auto);
|
|
}
|
|
|
|
public void Load(string path, FileFormat fileFormat)
|
|
{
|
|
this.Load(path, fileFormat, Encoding.Default);
|
|
}
|
|
|
|
public void Load(string path, FileFormat fileFormat, Encoding encoding)
|
|
{
|
|
bool flag = fileFormat == FileFormat._Auto;
|
|
if (flag)
|
|
{
|
|
foreach (KeyValuePair<FileFormat, IFileFormatProvider> keyValuePair in Workbook.FileFormatProviders)
|
|
{
|
|
bool flag2 = keyValuePair.Value.IsValidFormat(path);
|
|
if (flag2)
|
|
{
|
|
fileFormat = keyValuePair.Key;
|
|
break;
|
|
}
|
|
}
|
|
bool flag3 = fileFormat == FileFormat._Auto;
|
|
if (flag3)
|
|
{
|
|
throw new NotSupportedException("Cannot determine the file format to load workbook from specified path, try specify explicitly the file format by argument.");
|
|
}
|
|
}
|
|
using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
|
|
{
|
|
this.Load(fileStream, fileFormat, (encoding == null) ? Encoding.Default : encoding);
|
|
}
|
|
bool flag4 = fileFormat == FileFormat.CSV;
|
|
if (flag4)
|
|
{
|
|
bool flag5 = this.worksheets.Count > 0;
|
|
if (flag5)
|
|
{
|
|
this.worksheets[0].Name = Path.GetFileNameWithoutExtension(path);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Load(Stream stream, FileFormat fileFormat)
|
|
{
|
|
this.Load(stream, fileFormat, Encoding.Default);
|
|
}
|
|
|
|
public void Load(Stream stream, FileFormat fileFormat, Encoding encoding)
|
|
{
|
|
bool flag = fileFormat == FileFormat._Auto;
|
|
if (flag)
|
|
{
|
|
throw new ArgumentException("File format 'Auto' is invalid for loading workbook from stream, try specify a file format.");
|
|
}
|
|
IFileFormatProvider fileFormatProvider;
|
|
bool flag2 = !Workbook.FileFormatProviders.TryGetValue(fileFormat, out fileFormatProvider);
|
|
if (flag2)
|
|
{
|
|
throw new FileFormatNotSupportException("Specified file format is not supported.");
|
|
}
|
|
bool flag3 = this.controlAdapter != null;
|
|
if (flag3)
|
|
{
|
|
this.controlAdapter.ChangeCursor(CursorStyle.Busy);
|
|
}
|
|
bool flag4 = encoding == null;
|
|
if (flag4)
|
|
{
|
|
encoding = Encoding.Default;
|
|
}
|
|
try
|
|
{
|
|
fileFormatProvider.Load(this, stream, encoding, null);
|
|
}
|
|
finally
|
|
{
|
|
bool flag5 = this.controlAdapter != null;
|
|
if (flag5)
|
|
{
|
|
this.controlAdapter.ChangeCursor(CursorStyle.PlatformDefault);
|
|
}
|
|
EventHandler workbookLoaded = this.WorkbookLoaded;
|
|
if (workbookLoaded != null)
|
|
{
|
|
workbookLoaded(this, null);
|
|
}
|
|
}
|
|
}
|
|
|
|
////[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|
public event EventHandler WorkbookLoaded;
|
|
|
|
////[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|
public event EventHandler WorkbookSaved;
|
|
|
|
internal string GetAvailableWorksheetName()
|
|
{
|
|
int num = 1;
|
|
string result;
|
|
while (!this.CheckWorksheetName(result = LanguageResource.Sheet + num.ToString()))
|
|
{
|
|
num++;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public Worksheet CreateWorksheet(string name = null)
|
|
{
|
|
bool flag = string.IsNullOrEmpty(name);
|
|
if (flag)
|
|
{
|
|
name = this.GetAvailableWorksheetName();
|
|
}
|
|
else
|
|
{
|
|
this.ValidateWorksheetName(name);
|
|
}
|
|
Worksheet worksheet = new Worksheet(this, name);
|
|
EventHandler<WorksheetCreatedEventArgs> worksheetCreated = this.WorksheetCreated;
|
|
if (worksheetCreated != null)
|
|
{
|
|
worksheetCreated(this, new WorksheetCreatedEventArgs(worksheet));
|
|
}
|
|
return worksheet;
|
|
}
|
|
|
|
public void AddWorksheet(Worksheet sheet)
|
|
{
|
|
this.InsertWorksheet(this.worksheets.Count, sheet);
|
|
}
|
|
|
|
public void NewWorksheet(string name = null)
|
|
{
|
|
this.AddWorksheet(this.CreateWorksheet(name));
|
|
}
|
|
|
|
public void InsertWorksheet(int index, Worksheet sheet)
|
|
{
|
|
bool flag = index < 0 || index > this.worksheets.Count;
|
|
if (flag)
|
|
{
|
|
throw new ArgumentOutOfRangeException("index");
|
|
}
|
|
bool flag2 = sheet.Workbook != null && sheet.Workbook != this;
|
|
if (flag2)
|
|
{
|
|
throw new WorkbookException("Specified worksheet belongs to another workbook, remove from another workbook firstly.");
|
|
}
|
|
this.ValidateWorksheetName(sheet.Name);
|
|
this.worksheets.Insert(index, sheet);
|
|
sheet.workbook = this;
|
|
sheet.ControlAdapter = this.controlAdapter;
|
|
bool flag3 = this.sheetTab != null;
|
|
if (flag3)
|
|
{
|
|
this.sheetTab.InsertTab(index, sheet.Name);
|
|
bool flag4 = (this.worksheets.Count > 0 && this.sheetTab.SelectedIndex == -1) || this.sheetTab.SelectedIndex >= this.worksheets.Count;
|
|
if (flag4)
|
|
{
|
|
this.sheetTab.SelectedIndex = 0;
|
|
}
|
|
}
|
|
bool flag5 = this.controlAdapter != null && this.controlAdapter.ControlInstance.CurrentWorksheet == null;
|
|
if (flag5)
|
|
{
|
|
this.controlAdapter.ControlInstance.CurrentWorksheet = sheet;
|
|
}
|
|
EventHandler<WorksheetInsertedEventArgs> worksheetInserted = this.WorksheetInserted;
|
|
if (worksheetInserted != null)
|
|
{
|
|
worksheetInserted(this, new WorksheetInsertedEventArgs(sheet)
|
|
{
|
|
Index = index
|
|
});
|
|
}
|
|
}
|
|
|
|
public bool RemoveWorksheet(int index)
|
|
{
|
|
bool flag = index < 0 || index >= this.worksheets.Count;
|
|
if (flag)
|
|
{
|
|
throw new ArgumentOutOfRangeException("index");
|
|
}
|
|
bool flag2 = this.sheetTab != null;
|
|
if (flag2)
|
|
{
|
|
this.sheetTab.RemoveTab(index);
|
|
}
|
|
Worksheet worksheet = this.worksheets[index];
|
|
worksheet.workbook = null;
|
|
this.worksheets.RemoveAt(index);
|
|
EventHandler<WorksheetRemovedEventArgs> worksheetRemoved = this.WorksheetRemoved;
|
|
if (worksheetRemoved != null)
|
|
{
|
|
worksheetRemoved(this, new WorksheetRemovedEventArgs(worksheet));
|
|
}
|
|
IControlAdapter controlAdapter = this.controlAdapter;
|
|
if (controlAdapter != null)
|
|
{
|
|
controlAdapter.Invalidate();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool RemoveWorksheet(Worksheet sheet)
|
|
{
|
|
int num = this.worksheets.IndexOf(sheet);
|
|
bool flag = num < 0 || num >= this.worksheets.Count;
|
|
if (flag)
|
|
{
|
|
throw new WorksheetNotFoundException("Specified worksheet cannot be found.");
|
|
}
|
|
return this.RemoveWorksheet(num);
|
|
}
|
|
|
|
public Worksheet CopyWorksheet(int index, int newIndex, string newName = null)
|
|
{
|
|
bool flag = newIndex < 0 || newIndex > this.worksheets.Count;
|
|
if (flag)
|
|
{
|
|
throw new ArgumentOutOfRangeException("newIndex");
|
|
}
|
|
return this.CopyWorksheet(this.worksheets[index], newIndex, newName);
|
|
}
|
|
|
|
public Worksheet CopyWorksheet(Worksheet sheet, int newIndex, string newName = null)
|
|
{
|
|
bool flag = sheet.workbook != this;
|
|
if (flag)
|
|
{
|
|
throw new WorksheetNotFoundException("Specified worksheet does not belong to this workbook.");
|
|
}
|
|
bool flag2 = newIndex < 0 || newIndex > this.worksheets.Count;
|
|
if (flag2)
|
|
{
|
|
throw new ArgumentOutOfRangeException("newIndex");
|
|
}
|
|
Worksheet worksheet = sheet.Clone(newName);
|
|
bool flag3 = this.WorksheetCreated != null;
|
|
if (flag3)
|
|
{
|
|
this.WorksheetCreated(this, new WorksheetCreatedEventArgs(worksheet));
|
|
}
|
|
this.InsertWorksheet(newIndex, worksheet);
|
|
return worksheet;
|
|
}
|
|
|
|
public Worksheet MoveWorksheet(int index, int newIndex)
|
|
{
|
|
bool flag = index < 0 || index > this.worksheets.Count;
|
|
if (flag)
|
|
{
|
|
throw new ArgumentOutOfRangeException("index");
|
|
}
|
|
bool flag2 = newIndex < 0 || newIndex > this.worksheets.Count;
|
|
if (flag2)
|
|
{
|
|
throw new ArgumentOutOfRangeException("newIndex");
|
|
}
|
|
Worksheet worksheet = this.worksheets[index];
|
|
bool flag3 = index == newIndex;
|
|
Worksheet result;
|
|
if (flag3)
|
|
{
|
|
result = worksheet;
|
|
}
|
|
else
|
|
{
|
|
this.sheetTab.RemoveTab(index);
|
|
this.worksheets.RemoveAt(index);
|
|
this.worksheets.Insert(newIndex, worksheet);
|
|
this.sheetTab.InsertTab(newIndex, worksheet.Name);
|
|
result = worksheet;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public Worksheet MoveWorksheet(Worksheet sheet, int newIndex)
|
|
{
|
|
bool flag = sheet.workbook != this;
|
|
if (flag)
|
|
{
|
|
throw new WorksheetNotFoundException("Specified worksheet does not belong to this workbook.");
|
|
}
|
|
int worksheetIndex = this.GetWorksheetIndex(sheet);
|
|
return this.MoveWorksheet(worksheetIndex, newIndex);
|
|
}
|
|
|
|
public int GetWorksheetIndex(Worksheet sheet)
|
|
{
|
|
return this.worksheets.IndexOf(sheet);
|
|
}
|
|
|
|
public int GetWorksheetIndex(string name)
|
|
{
|
|
Worksheet worksheetByName = this.GetWorksheetByName(name);
|
|
return (worksheetByName == null) ? -1 : this.GetWorksheetIndex(worksheetByName);
|
|
}
|
|
|
|
public Worksheet GetWorksheetByName(string name)
|
|
{
|
|
return this.worksheets.FirstOrDefault((Worksheet w) => string.Compare(w.Name, name, true) == 0);
|
|
}
|
|
|
|
public WorksheetCollection Worksheets
|
|
{
|
|
get
|
|
{
|
|
bool flag = this.worksheetCollection == null;
|
|
if (flag)
|
|
{
|
|
this.worksheetCollection = new WorksheetCollection(this);
|
|
}
|
|
return this.worksheetCollection;
|
|
}
|
|
}
|
|
|
|
//[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|
public event EventHandler<WorksheetCreatedEventArgs> WorksheetCreated;
|
|
|
|
//[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|
public event EventHandler<WorksheetInsertedEventArgs> WorksheetInserted;
|
|
|
|
//[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|
public event EventHandler<WorksheetRemovedEventArgs> WorksheetRemoved;
|
|
|
|
//[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|
public event EventHandler<WorksheetNameChangingEventArgs> BeforeWorksheetNameChange;
|
|
|
|
//[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|
public event EventHandler<WorksheetNameChangingEventArgs> WorksheetNameChanged;
|
|
|
|
//[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|
public event EventHandler<WorksheetEventArgs> WorksheetNameBackColorChanged;
|
|
|
|
//[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|
public event EventHandler<WorksheetEventArgs> WorksheetNameTextColorChanged;
|
|
|
|
internal bool CheckWorksheetName(string name)
|
|
{
|
|
return this.worksheets.All((Worksheet s) => string.Compare(s.Name, name, true) != 0);
|
|
}
|
|
|
|
internal void ValidateWorksheetName(string name)
|
|
{
|
|
bool flag = !this.CheckWorksheetName(name);
|
|
if (flag)
|
|
{
|
|
throw new Exception("Specified name is already used by another worksheet.");
|
|
}
|
|
}
|
|
|
|
internal string NotifyWorksheetNameChange(Worksheet sheet, string name)
|
|
{
|
|
bool flag = this.BeforeWorksheetNameChange != null;
|
|
string result;
|
|
if (flag)
|
|
{
|
|
WorksheetNameChangingEventArgs worksheetNameChangingEventArgs = new WorksheetNameChangingEventArgs(sheet, name);
|
|
this.BeforeWorksheetNameChange(this, worksheetNameChangingEventArgs);
|
|
result = worksheetNameChangingEventArgs.NewName;
|
|
}
|
|
else
|
|
{
|
|
result = name;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
internal void RaiseWorksheetNameChangedEvent(Worksheet worksheet)
|
|
{
|
|
int worksheetIndex = this.GetWorksheetIndex(worksheet);
|
|
bool flag = worksheetIndex >= 0 && worksheetIndex < this.worksheets.Count;
|
|
if (flag)
|
|
{
|
|
bool flag2 = this.sheetTab != null;
|
|
if (flag2)
|
|
{
|
|
this.sheetTab.UpdateTab(worksheetIndex, worksheet.Name, worksheet.NameBackColor, worksheet.NameTextColor);
|
|
}
|
|
bool flag3 = this.WorksheetNameChanged != null;
|
|
if (flag3)
|
|
{
|
|
this.WorksheetNameChanged(this, new WorksheetNameChangingEventArgs(worksheet, worksheet.Name));
|
|
}
|
|
}
|
|
}
|
|
|
|
internal void RaiseWorksheetNameBackColorChangedEvent(Worksheet worksheet)
|
|
{
|
|
int worksheetIndex = this.GetWorksheetIndex(worksheet);
|
|
bool flag = worksheetIndex >= 0 && worksheetIndex < this.worksheets.Count;
|
|
if (flag)
|
|
{
|
|
bool flag2 = this.sheetTab != null;
|
|
if (flag2)
|
|
{
|
|
this.sheetTab.UpdateTab(worksheetIndex, worksheet.Name, worksheet.NameBackColor, worksheet.NameTextColor);
|
|
}
|
|
bool flag3 = this.WorksheetNameBackColorChanged != null;
|
|
if (flag3)
|
|
{
|
|
this.WorksheetNameBackColorChanged(this, new WorksheetEventArgs(worksheet));
|
|
}
|
|
}
|
|
}
|
|
|
|
internal void RaiseWorksheetNameTextColorChangedEvent(Worksheet worksheet)
|
|
{
|
|
int worksheetIndex = this.GetWorksheetIndex(worksheet);
|
|
bool flag = worksheetIndex >= 0 && worksheetIndex < this.worksheets.Count;
|
|
if (flag)
|
|
{
|
|
bool flag2 = this.sheetTab != null;
|
|
if (flag2)
|
|
{
|
|
this.sheetTab.UpdateTab(worksheetIndex, worksheet.Name, worksheet.NameBackColor, worksheet.NameTextColor);
|
|
}
|
|
bool flag3 = this.WorksheetNameTextColorChanged != null;
|
|
if (flag3)
|
|
{
|
|
this.WorksheetNameTextColorChanged(this, new WorksheetEventArgs(worksheet));
|
|
}
|
|
}
|
|
}
|
|
|
|
internal void RaiseWorksheetScrolledEvent(Worksheet worksheet, float x, float y)
|
|
{
|
|
bool flag = this.controlAdapter != null && this.controlAdapter.ControlInstance != null;
|
|
if (flag)
|
|
{
|
|
this.controlAdapter.ControlInstance.RaiseWorksheetScrolledEvent(worksheet, x, y);
|
|
}
|
|
}
|
|
|
|
internal void ClearWorksheets()
|
|
{
|
|
while (this.worksheets.Count > 0)
|
|
{
|
|
Worksheet worksheet = this.worksheets[this.worksheets.Count - 1];
|
|
this.worksheets.Remove(worksheet);
|
|
worksheet.workbook = null;
|
|
bool flag = this.WorksheetRemoved != null;
|
|
if (flag)
|
|
{
|
|
this.WorksheetRemoved(this, new WorksheetRemovedEventArgs(worksheet));
|
|
}
|
|
}
|
|
bool flag2 = this.sheetTab != null;
|
|
if (flag2)
|
|
{
|
|
this.sheetTab.ClearTabs();
|
|
}
|
|
Debug.Assert(this.worksheets.Count == 0);
|
|
}
|
|
|
|
public int WorksheetCount
|
|
{
|
|
get
|
|
{
|
|
return this.worksheets.Count;
|
|
}
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
this.ClearWorksheets();
|
|
this.AddWorksheet(this.CreateWorksheet(null));
|
|
}
|
|
|
|
public bool IsEmpty
|
|
{
|
|
get
|
|
{
|
|
foreach (Worksheet worksheet in this.worksheets)
|
|
{
|
|
bool flag = worksheet.MaxContentRow > 0 || worksheet.MaxContentCol > 0;
|
|
if (flag)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
internal void AttachSheetTabControl(ISheetTabControl sheetTab)
|
|
{
|
|
this.sheetTab = sheetTab;
|
|
this.sheetTab.NewSheetClick += this.sheetTab_NewSheetClick;
|
|
}
|
|
|
|
internal void DetechSheetTabControl()
|
|
{
|
|
bool flag = this.sheetTab != null;
|
|
if (flag)
|
|
{
|
|
this.sheetTab.NewSheetClick -= this.sheetTab_NewSheetClick;
|
|
this.sheetTab = null;
|
|
}
|
|
}
|
|
|
|
private void sheetTab_NewSheetClick(object sender, EventArgs e)
|
|
{
|
|
Worksheet worksheet = this.CreateWorksheet(null);
|
|
bool flag = worksheet != null;
|
|
if (flag)
|
|
{
|
|
this.AddWorksheet(worksheet);
|
|
this.sheetTab.SelectedIndex = this.worksheets.Count - 1;
|
|
}
|
|
}
|
|
|
|
private void sheetTab_TabMoved(object sender, SheetTabMovedEventArgs e)
|
|
{
|
|
Worksheet item = this.worksheets[e.Index];
|
|
this.worksheets.RemoveAt(e.Index);
|
|
int num = e.TargetIndex;
|
|
bool flag = num > e.Index;
|
|
if (flag)
|
|
{
|
|
num--;
|
|
}
|
|
this.worksheets.Insert(num, item);
|
|
}
|
|
|
|
public void SetSettings(WorkbookSettings settings, bool value)
|
|
{
|
|
if (value)
|
|
{
|
|
bool flag = (this.settings & settings) != settings;
|
|
if (flag)
|
|
{
|
|
this.settings |= settings;
|
|
bool flag2 = this.SettingsChanged != null;
|
|
if (flag2)
|
|
{
|
|
this.SettingsChanged(this, null);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool flag3 = (this.settings & settings) > WorkbookSettings.None;
|
|
if (flag3)
|
|
{
|
|
this.settings &= ~settings;
|
|
bool flag4 = this.SettingsChanged != null;
|
|
if (flag4)
|
|
{
|
|
this.SettingsChanged(this, null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public WorkbookSettings GetSettings()
|
|
{
|
|
return this.settings;
|
|
}
|
|
|
|
public bool HasSettings(WorkbookSettings settings)
|
|
{
|
|
return this.settings.Has(settings);
|
|
}
|
|
|
|
//[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|
public event EventHandler SettingsChanged;
|
|
|
|
//[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|
public event EventHandler<ExceptionHappenEventArgs> ExceptionHappened;
|
|
|
|
public void NotifyExceptionHappen(Worksheet sheet, Exception ex)
|
|
{
|
|
Logger.Log("workbook", "internal exception: " + ex.Message);
|
|
bool flag = this.ExceptionHappened != null;
|
|
if (flag)
|
|
{
|
|
this.ExceptionHappened(this, new ExceptionHappenEventArgs(sheet, ex));
|
|
}
|
|
}
|
|
|
|
public PrintSession CreatePrintSession()
|
|
{
|
|
PrintSession printSession = new PrintSession();
|
|
foreach (Worksheet item in this.worksheets)
|
|
{
|
|
printSession.worksheets.Add(item);
|
|
}
|
|
printSession.Init();
|
|
return printSession;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
bool flag = this.sheetTab != null;
|
|
if (flag)
|
|
{
|
|
this.DetechSheetTabControl();
|
|
this.sheetTab = null;
|
|
}
|
|
this.Clear();
|
|
}
|
|
|
|
internal List<Worksheet> worksheets = new List<Worksheet>();
|
|
|
|
internal IControlAdapter controlAdapter;
|
|
|
|
private bool isReadonly = false;
|
|
|
|
public static readonly Dictionary<FileFormat, IFileFormatProvider> FileFormatProviders = new Dictionary<FileFormat, IFileFormatProvider>();
|
|
|
|
private WorksheetCollection worksheetCollection;
|
|
|
|
private ISheetTabControl sheetTab;
|
|
|
|
private WorkbookSettings settings = WorkbookSettings.Default;
|
|
}
|
|
}
|