Ejemplo n.º 1
0
        public static string HtmlClipboardFragment(object[][] data, string Title, ColumnInfo[] ColumnInfos)
        {
            const string OffsetFormat     = "0000000000";
            const string CFHeaderTemplate =
                "Version:1.0\r\n" +
                "StartHTML:{0}\r\n" +
                "EndHTML:{1}\r\n" +
                "StartFragment:{2}\r\n" +
                "EndFragment:{3}\r\n";

            const string HtmlHeader =
                "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n" +
                "<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n" +
                "<body>\r\n" +
                "<!--StartFragment-->\r\n";

            const string HtmlFooter =
                "<!--EndFragment-->\r\n" +
                "</body>\r\n" +
                "</html>";

            string html = ExportFormatter.HtmlTable(data, Title, ColumnInfos);

            int CFHeaderLength = string.Format(CFHeaderTemplate, OffsetFormat, OffsetFormat, OffsetFormat, OffsetFormat).Length;
            int startFragment  = CFHeaderLength + HtmlHeader.Length;
            int endFragment    = startFragment + html.Length;
            int endHTML        = endFragment + HtmlFooter.Length;

            string CfHtml = string.Format(CFHeaderTemplate, CFHeaderLength.ToString(OffsetFormat), endHTML.ToString(OffsetFormat), startFragment.ToString(OffsetFormat), endFragment.ToString(OffsetFormat));

            return(CfHtml + HtmlHeader + html + HtmlFooter);
        }
Ejemplo n.º 2
0
        public void AppendInfo(ColumnInfo[] columnInfos,
                               IEnumerable <IExportable> results,
                               string title,
                               ClipboardWriterAppendingInformationFormat appendingInformationFormat)
        {
            object[][] resultsAsArray = results.Select(result => result.ToArray()).ToArray();

            if (appendingInformationFormat.HasFlag(ClipboardWriterAppendingInformationFormat.XmlSpreadsheetFormat))
            {
                const string xmlSpreadsheetDataFormat = "XML Spreadsheet";
                using (var stream = ExportFormatter.XmlSpreadsheetNew(resultsAsArray, title, columnInfos))
                {
                    AppendStream(DataFormats.GetDataFormat(xmlSpreadsheetDataFormat).Name, stream);
                }
            }

            if (appendingInformationFormat.HasFlag(ClipboardWriterAppendingInformationFormat.RtfFormat))
            {
                AppendString(DataFormats.Rtf, ExportFormatter.RTF(resultsAsArray, title));
            }

            if (appendingInformationFormat.HasFlag(ClipboardWriterAppendingInformationFormat.HtmlFormat))
            {
                AppendString(DataFormats.Html, ExportFormatter.HtmlClipboardFragment(resultsAsArray, title, columnInfos));
            }

            if (appendingInformationFormat.HasFlag(ClipboardWriterAppendingInformationFormat.CsvFormat))
            {
                AppendString(DataFormats.CommaSeparatedValue, ExportFormatter.Csv(resultsAsArray, title, columnInfos));
            }

            if (appendingInformationFormat.HasFlag(ClipboardWriterAppendingInformationFormat.UnicodeFormat) && results is IEnumerable <IExportable> unicodeResults)
            {
                var unicodeTextFormat = title + Environment.NewLine + string.Join(string.Empty, unicodeResults.Select(result => result.ToClipboardString() + Environment.NewLine).ToArray());
                AppendString(DataFormats.UnicodeText, unicodeTextFormat);
            }
        }