示例#1
0
        public override void Process(iExcel owner, ref Workbook book, ref Worksheet sheet)
        {
            try
            {
                if (book != null && !string.IsNullOrEmpty(Title))
                {
                    sheet = new Worksheet(Title);
                    //sheet.PageSetup.PrintRepeatRows = 2;
                    //sheet.PageSetup.PrintRepeatColumns = 2;

                    if (Style != null)
                    {
                        if (Style["Orientation"] != null)
                        {
                            if (((string)Style["Orientation"]).ToLower() == "landscape")
                            {
                                sheet.PageSetup.Orientation = Orientation.Landscape;
                            }
                            else if (((string)Style["Orientation"]).ToLower() == "portrait")
                            {
                                sheet.PageSetup.Orientation = Orientation.Portrait;
                            }
                        }
                    }
                    book.Add(sheet);
                }
            }
            catch (Exception ex) { Log.Trace(ex.Message, ex.StackTrace); }
        }
示例#2
0
        protected override bool ProcessRequest(CefRequest request, CefCallback callback)
        {
            Task task = new Task(() =>
            {
                try
                {
                    //var serializer = new JavaScriptSerializer();
                    //serializer.MaxJsonLength = Int32.MaxValue;
                    //serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
                    var excel      = new iExcel(configuration.Application, Environment.CurrentDirectory, JsonMapper.ToObject <object>(excelString));
                    var excelBytes = Data = iExcel.CreateExcel(excel);

                    var dir = Environment.CurrentDirectory + "\\Web\\" + configuration.Application + "\\reports";
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    var dt   = DateTime.Now.ToString("yyyyMMddHmmssfff");
                    var file = excel.Properties.Title.Replace(" ", "_") + "_" + dt + "_" + excel.Properties.Items + ".xlsx";
                    var path = dir + "\\" + file;
                    File.WriteAllBytes(path, excelBytes);

                    var echo = JsonMapper.ToJson(new FileHelper("OK", "reports/" + file, excel.Properties.Title, excel.Properties.Items));

                    Data = Encoding.UTF8.GetBytes(echo);
                }
                catch (Exception ex)
                {
                    Log.Trace(ex.Message, ex.StackTrace);
                    var echo = JsonMapper.ToJson(new ErrorHelper(ex.Message, ex.StackTrace));

                    Data = Encoding.UTF8.GetBytes(echo);
                }

                callback.Continue();
            });

            task.Start();
            return(true);
        }
示例#3
0
 public virtual void Process(iExcel owner, ref Workbook book, ref Worksheet sheet)
 {
 }
示例#4
0
        public override void Process(iExcel owner, ref Workbook book, ref Worksheet sheet)
        {
            try
            {
                if (sheet != null && Content != null && X > -1 && Y > -1)
                {
                    sheet.Cells[X, Y].Value = Content.ToString();

                    if (Content.IsNumber())
                    {
                        sheet.Cells[X, Y].Format = BuiltInCellFormat.NumberNoDecimalPlaces;
                    }
                    else
                    {
                        sheet.Cells[X, Y].Format = BuiltInCellFormat.Text;
                    }

                    if (Style != null)
                    {
                        try { if (Style["FontName"] != null)
                              {
                                  sheet.Cells[X, Y].FontName = (string)Style["FontName"];
                              }
                        } catch { }
                        try { if (Style["Bold"] != null)
                              {
                                  sheet.Cells[X, Y].Bold = (bool)Style["Bold"];
                              }
                        } catch { }
                        try { if (Style["FontSize"] != null)
                              {
                                  sheet.Cells[X, Y].FontSize = (int)Style["Bold"];
                              }
                        } catch { }
                        try { if (Style["Format"] != null)
                              {
                                  sheet.Cells[X, Y].Format = (string)Style["Format"];
                              }
                        } catch { }
                        try { if (Style["Hyperlink"] != null)
                              {
                                  sheet.Cells[X, Y].Hyperlink = (string)Style["Hyperlink"];
                              }
                        } catch { }
                        try { if (Style["Italic"] != null)
                              {
                                  sheet.Cells[X, Y].Italic = (bool)Style["Italic"];
                              }
                        } catch { }
                        try { if (Style["Underline"] != null)
                              {
                                  sheet.Cells[X, Y].Underline = (bool)Style["Underline"];
                              }
                        } catch { }
                        try {
                            if (Style["TextColor"] != null)
                            {
                                var col = System.Drawing.ColorTranslator.FromHtml((string)Style["TextColor"]);
                                sheet.Cells[X, Y].TextColor = col; // Simplexcel.Color.FromArgb(col.A, col.R, col.G, col.B);
                            }
                        } catch { }
                    }
                }
            }
            catch (Exception ex) { Log.Trace(ex.Message, ex.StackTrace); }
        }