コード例 #1
0
        protected virtual void DoWriteSpreadTable(Document book, SpreadTableOptions options, string htmlTable)
        {
            var range     = book.AppendHtmlText(htmlTable, DevExpress.XtraRichEdit.API.Native.InsertOptions.KeepSourceFormatting);
            var paragraph = book.Paragraphs.Append();

            book.CaretPosition = paragraph.Range.End;
            Script.Book.SCBook.ResetBookFormatting(book, book.CaretPosition);
            ScrollToCaret();

            Script.Book.SCBook.AddComments(book, range, options);

            WriteRangeToConsole(book, range);
        }
コード例 #2
0
        protected virtual string GenerateTableHtml(SpreadTableOptions options)
        {
            string    htmlTable;
            IWorkbook workbook        = null;
            bool      disposeWorkbook = false;

            try
            {
                if (options._Spreadsheet != null)
                {
                    workbook = options._Spreadsheet.Workbook;
                }
                else if (!string.IsNullOrWhiteSpace(options._FileName))
                {
                    disposeWorkbook = true;

                    string fileName = Project.Current.MapPath(options._FileName);
                    if (!File.Exists(fileName))
                    {
                        throw new Exception($"File '{fileName}' does not exist.");
                    }

                    workbook = SpreadsheetUtils.CreateWorkbook();
                    workbook.LoadDocument(fileName);
                }
                else
                {
                    workbook = Host?.Spreadsheet?.Workbook;
                }

                if (workbook == null)
                {
                    throw new Exception("Spreadsheet is not specified");
                }

                var range = SpreadsheetUtils.GetWorkbookRange(workbook, options._TableName);

                var optionsHtml = new DevExpress.XtraSpreadsheet.Export.HtmlDocumentExporterOptions()
                {
                    SheetIndex = workbook.Sheets.IndexOf(range.Worksheet),
                    Range      = range.GetReferenceA1(),
                    Encoding   = Encoding.Unicode
                };

                using var stream = new MemoryStream();
                workbook.ExportToHtml(stream, optionsHtml);
                stream.Seek(0, SeekOrigin.Begin);

                using var reader = new StreamReader(stream, Encoding.UTF8);
                htmlTable        = reader.ReadToEnd();
            }
            finally
            {
                if (disposeWorkbook)
                {
                    workbook?.Dispose();
                }
            }

            return(htmlTable);
        }
コード例 #3
0
        protected virtual void DoWriteSpreadTable(Spreadsheet.SCSpreadsheet spreadsheet, string fileName, string tableName, SpreadTableOptions options)
        {
            options ??= new SpreadTableOptions();

            options._Spreadsheet = spreadsheet;
            options._FileName    = fileName;
            options._TableName   = tableName;

            var book = options.Book?.Document ?? Document;

            string htmlTable = null;

            if ((spreadsheet == null && !string.IsNullOrWhiteSpace(fileName)) || spreadsheet != Host?.Spreadsheet)
            {
                htmlTable = GenerateTableHtml(options);
            }

            ExecuteSynchronized(() =>
            {
                if (htmlTable == null)
                {
                    htmlTable = GenerateTableHtml(options);
                }
                DoWriteSpreadTable(book, options, htmlTable);
            });
        }
コード例 #4
0
 public SCBook WriteSpreadTable(Spreadsheet.SCSpreadsheet spreadsheet, string tableName, SpreadTableOptions options = null)
 {
     DoWriteSpreadTable(spreadsheet, null, tableName, options); return(this);
 }
コード例 #5
0
 public SCBook WriteSpreadTable(string fileName, string tableName, SpreadTableOptions options = null)
 {
     DoWriteSpreadTable(null, fileName, tableName, options); return(this);
 }