protected virtual void DoSelectSheet(string sheetName, int?sheetIndex, SpreadsheetOptions options)
        {
            var spread = options?.Spreadsheet?.Workbook ?? Workbook;

            Sheet sheet = null;

            if (!string.IsNullOrWhiteSpace(sheetName))
            {
                sheet = spread.Sheets[sheetName];
            }
            else if (sheetIndex.HasValue)
            {
                int sheetCount = spread.Sheets.Count;
                int index      = sheetIndex.Value;
                if (index < 0)
                {
                    index = sheetCount + 1 - index;    //-1 means last sheet, -2 - one before last etc.
                }
                index = Code.Utils.ValueInRange(index, 1, sheetCount);

                sheet = spread.Sheets[index - 1];  //Use 1-based sheet index
            }

            if (sheet != null)
            {
                spread.Sheets.ActiveSheet = sheet;
            }
        }
        protected virtual void DoGetWorksheetNames(SpreadsheetOptions options, out string[] result)
        {
            var spread = options?.Spreadsheet?.Workbook ?? Workbook;

            var sheetNames = new List <string>();

            foreach (var worksheet in spread.Worksheets)
            {
                sheetNames.Add(worksheet.Name);
            }

            result = sheetNames.ToArray();
        }
Пример #3
0
        protected virtual void DoClear(SpreadsheetOptions options)
        {
            var spread = options?.Spreadsheet?.Workbook ?? Workbook;

            var newSheet = spread.Worksheets.Add();

            while (spread.ChartSheets.Count > 0)
            {
                spread.ChartSheets.RemoveAt(0);
            }

            while (spread.Worksheets.Count > 1)
            {
                spread.Worksheets.RemoveAt(0);
            }

            newSheet.Name = "Sheet1";
        }
Пример #4
0
 public SCSpreadsheet Clear(SpreadsheetOptions options = null)
 {
     ExecuteSynchronized(options, () => DoClear(options));
     return(this);
 }
Пример #5
0
        protected virtual void DoMerge(SCSpreadsheet spreadsheet, SpreadsheetOptions options)
        {
            var spread = options?.Spreadsheet?.Workbook ?? Workbook;

            spread.Append(spreadsheet.Workbook);
        }
Пример #6
0
 public SCSpreadsheet Merge(SCSpreadsheet spreadsheet, SpreadsheetOptions options = null)
 {
     ExecuteSynchronized(options, () => DoMerge(spreadsheet, options));
     return(this);
 }
Пример #7
0
        protected override bool NeedSynchronization(SpreadsheetOptions options)
        {
            bool result = base.NeedSynchronization(options);

            return(result);
        }
 public SCSpreadsheet SelectSheet(int sheetIndex, SpreadsheetOptions options = null)
 {
     ExecuteSynchronized(options, () => DoSelectSheet(null, sheetIndex, options));
     return(this);
 }
 public SCSpreadsheet SelectSheet(string sheetName, SpreadsheetOptions options = null)
 {
     ExecuteSynchronized(options, () => DoSelectSheet(sheetName, null, options));
     return(this);
 }
 public string[] GetWorksheetNames(SpreadsheetOptions options = null)
 {
     string[] sheetNames = null;
     ExecuteSynchronized(options, () => DoGetWorksheetNames(options, out sheetNames));
     return(sheetNames);
 }