当前位置: 首页>>代码示例>>C#>>正文


C# Workbook.SaveToStream方法代码示例

本文整理汇总了C#中Workbook.SaveToStream方法的典型用法代码示例。如果您正苦于以下问题:C# Workbook.SaveToStream方法的具体用法?C# Workbook.SaveToStream怎么用?C# Workbook.SaveToStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Workbook的用法示例。


在下文中一共展示了Workbook.SaveToStream方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetScrumDailyReport

        public Stream GetScrumDailyReport(DateTime dateFrom, DateTime dateTo)
        {
            try
            {
                var wb = new Workbook();
                var templatePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
                templatePath = templatePath.Remove(0, 6);

                PrepareExcel(ref wb, templatePath);
                var fileName = "";

                var dt = GetData(dateFrom, dateTo);
                if (dt == null || dt.Count == 0)
                    return null;

                FillSheet(wb, dt, dateFrom, dateTo);

                wb.Worksheets.RemoveAt(0);
                wb.Worksheets.ActiveSheetIndex = 0;

                return wb.SaveToStream();
            }
            catch (Exception ex)
            {
                _logger.ErrorFormat("Exception: {0}", ex);
                return null;
            }
        }
开发者ID:cybind,项目名称:Scrum-Molder,代码行数:28,代码来源:ReportManager.cs

示例2: LoadProfilesGrid_RowCommand

        protected void LoadProfilesGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                var loadProfileId = new Guid(e.CommandArgument.ToString());
                Response.Redirect("Edit.aspx?id=" + loadProfileId);
            }
            else if (e.CommandName == "Export")
            {
                var loadProfileRepository = IoC.Resolve<IRepository<Model.Simulation.LoadProfile>>();
                var loadProfile = loadProfileRepository.Get(new Guid(e.CommandArgument.ToString()));
                var workbook  = new Workbook();
                var sheet = workbook.Worksheets[0];
                sheet.Cells.Merge(0, 0, 1, 5);
                sheet.Cells[0, 0].PutValue(loadProfile.Name + " - " + loadProfile.Description);
                sheet.Cells[1, 0].PutValue("Start Date");
                sheet.Cells[1, 1].PutValue("Start Time");
                sheet.Cells[1, 2].PutValue("End Date");
                sheet.Cells[1, 3].PutValue("End Time");
                sheet.Cells[1, 4].PutValue("Consumption (kwh)");

                int rowIndex = 2;
                foreach (var data in loadProfile.Data)
                {
                    sheet.Cells[rowIndex, 0].PutValue(data.StartTime.ToShortDateString());
                    sheet.Cells[rowIndex, 1].PutValue(data.StartTime.ToShortTimeString());
                    sheet.Cells[rowIndex, 2].PutValue(data.EndTime.ToShortDateString());
                    sheet.Cells[rowIndex, 3].PutValue(data.EndTime.ToShortTimeString());
                    sheet.Cells[rowIndex, 4].PutValue(data.Consumption);
                    rowIndex++;
                }

                var outputFile = workbook.SaveToStream();
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + loadProfile.Name + ".xls");
                Response.AppendHeader("Content-Length", outputFile.Length.ToString());
                Response.ContentType = "application/ms-excel";
                outputFile.WriteTo(Response.OutputStream);
            }
            else if (e.CommandName == "DeleteLoadProfile")
            {
                var loadProfileId = new Guid(e.CommandArgument.ToString());

                using (var tran = UnitOfWork.Current.BeginTransaction())
                {
                    var loadProfileRepository = IoC.Resolve<IRepository<Model.Simulation.LoadProfile>>();

                    var loadProfile = loadProfileRepository.Load(loadProfileId);
                    loadProfileRepository.Delete(loadProfile);

                    tran.Commit();
                    UnitOfWork.Current.TransactionalFlush();

                    SuccessMessage.Text = loadProfile.Name + " deleted successfully.";
                }

                PopulateLoadProfilesGrid();
            }
        }
开发者ID:enct,项目名称:simulatortool,代码行数:58,代码来源:List.aspx.cs

示例3: ResponseExcel

 public static void ResponseExcel(Workbook workbook, string fileName)
 {
     MemoryStream ms = workbook.SaveToStream();
     HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding("GB2312");
     HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8) + ".xls");
     HttpContext.Current.Response.ContentType = "application/ms-excel";
     HttpContext.Current.Response.BinaryWrite(ms.ToArray());
     ms.Flush();
     ms.Position = 0;
 }
开发者ID:cityjoy,项目名称:DapperCodeSmith,代码行数:10,代码来源:ExcelHelper.cs

示例4: btnRun_Click

		private void btnRun_Click(object sender, System.EventArgs e)
		{
			Workbook workbook = new Workbook();
			Worksheet sheet = workbook.Worksheets[0];

			sheet.Range["C10"].Text = "The sample demonstrates how to save an excel workbook to stream.";

			//Save an excel workbook to stream
			FileStream fileStream = new FileStream("Sample.xls",FileMode.Create);
			workbook.SaveToStream(fileStream);

			fileStream.Close();

			ExcelDocViewer(Path.Combine(Application.StartupPath,"Sample.xls"));
		}
开发者ID:e-iceblue,项目名称:Spire.Office-for-.NET,代码行数:15,代码来源:Form1.cs

示例5: GetPrint

        public ActionResult GetPrint(string Report, int CountryID, int InstitutionID, int RecordID, int NumSample)
        {
            try
            {
                var ms = new MemoryStream();
                var pdfs = new MemoryStream();
                //var user = UserManager.FindById(User.Identity.GetUserId());
                int CountryID_ = CountryID;
                int? HospitalID_ = InstitutionID;
                int? RecordID_ = RecordID;
                int? NumSample_ = NumSample;
                string Path_Print = ConfigurationManager.AppSettings["PathPrintTest"];
                string Sample_Print_ = "Imp_Mue_" + RecordID_.ToString() + "_" + NumSample_.ToString() + "_" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm");

                if (Report == "" )
                {
                    ViewBag.Message = "El reporte no se pudo generar, por favor intente de nuevo";
                    return null;
                    ;
                }
                using (var fs = System.IO.File.OpenRead(ConfigurationManager.AppSettings["PrintTestTemplate"]
                    .Replace("{countryId}", CountryID_.ToString())
                    ))
                {
                    using (var excelPackage = new ExcelPackage(fs))
                    {
                        var excelWorkBook = excelPackage.Workbook;
                        int startColumn = 1;
                        int startRow = 1;
                        bool insertRow = false;

                        AppendDataToExcel(CountryID_, RecordID_, NumSample_, HospitalID_, excelWorkBook, Report, startRow, startColumn, 1, insertRow);

                        var excelPackage_Print = excelPackage;

                        excelPackage.SaveAs(ms);

                    }
                }

                ms.Position = 0;
                //FileStream file = new FileStream(Path_Print + Sample_Print_ + ".xlsx", FileMode.Create, FileAccess.Write);
                //ms.WriteTo(file);
                //file.Close();

                try
                {
                    // Conversion a PDF
                    // Create COM Objects
                    //Microsoft.Office.Interop.Excel.Application excelApplication;
                    //Microsoft.Office.Interop.Excel.Workbook excelWorkbook;

                    // Create new instance of Excel
                    //excelApplication = new Microsoft.Office.Interop.Excel.Application();

                    //excelApplication.Visible = false;
                    //excelApplication.ScreenUpdating = false;
                    //// Make the process silent
                    //excelApplication.DisplayAlerts = false;

                    //// Open the workbook that you wish to export to PDF
                    //excelWorkbook = excelApplication.Workbooks.Open(Path_Print + Sample_Print_ + ".xlsx");

                    ////    excelWorkbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, Path_Print + Sample_Print_ + ".pdf");

                    ////    // Close the workbook, quit the Excel, and clean up regardless of the results...
                    //excelWorkbook.Close();
                    //excelApplication.Quit();

                    //    excelApplication = null;
                    //    excelWorkbook = null;

                    Workbook workbook = new Workbook();

                    workbook.LoadFromStream(ms);
                    workbook.SaveToFile(Path_Print + Sample_Print_ + ".pdf", Spire.Xls.FileFormat.PDF);
                    workbook.SaveToStream(pdfs,Spire.Xls.FileFormat.PDF);

                }
                catch (System.Exception ex)
                {
                    string sSource;
                    string sLog;
                    string sEvent;

                    sSource = "PAHOFLU";
                    sLog = "sLog";
                    sEvent = ex.Message.ToString();

                    if (!EventLog.SourceExists(sSource))
                        EventLog.CreateEventSource(sSource, sLog);

                    EventLog.WriteEntry(sSource, sEvent);
                    //Console.Write("PAHOFLU - " + ex.Message);
                }

                // Esto fue desactivado porque ya no necesito grabarlo a disco
                //System.IO.File.Delete(Path_Print + Sample_Print_ + ".xlsx");

                //var pdfContent = new MemoryStream(System.IO.File.ReadAllBytes(Path_Print + Sample_Print_ + ".xlsx"));
//.........这里部分代码省略.........
开发者ID:jmancio,项目名称:PAHOFLUCR,代码行数:101,代码来源:PrintTestController.cs

示例6: WriteFormulas


//.........这里部分代码省略.........
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=WEEKDAY(3)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=YEAR(23)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=NOT(true)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=OR(true)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=AND(TRUE)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=VALUE(30)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=LEN(\"world\")";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=MID(\"world\",4,2)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=ROUND(7,3)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=SIGN(4)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=INT(200)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=ABS(-1.21)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=LN(15)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=EXP(20)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=SQRT(40)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=PI()";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=COS(9)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=SIN(45)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=MAX(10,30)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=MIN(5,7)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=AVERAGE(12,45)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=SUM(18,29)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            currentFormula = "=IF(4,2,2)";
            sheet.Range[currentRow, 1].Text = currentFormula;
            sheet.Range[currentRow++, 2].Formula = currentFormula;

            MemoryStream buffer = new MemoryStream();
            workbook.SaveToStream(buffer);
            buffer.Position = 0;

            return buffer;
        }
开发者ID:e-iceblue,项目名称:Spire.Office-for-.NET,代码行数:101,代码来源:Form1.cs

示例7: Main

        static void Main(string[] args)
        {
            //Create a workbook
            Workbook wb = new Workbook();

            //Add an excel chart
            int chartSheetIndex = AddExcelChartInWorkbook(wb);

            wb.Worksheets.SetOleSize(0, 5, 0, 5);

            Bitmap imgChart = wb.Worksheets[chartSheetIndex].Charts[0].ToImage();

            //Save the workbook to stream
            MemoryStream wbStream = wb.SaveToStream();

            //Create a presentation
            PresentationEx pres = new PresentationEx();
            SlideEx sld = pres.Slides[0];

            //Add the workbook on slide
            AddExcelChartInPresentation(pres, sld, wbStream, imgChart);

            //Write the output presentation on disk
            pres.Write("chart.pptx");
        }
开发者ID:horazius17,项目名称:Aspose_Slides_NET,代码行数:25,代码来源:Program.cs

示例8: export_Click

        protected void export_Click(object sender, EventArgs e)
        {
            Workbook workbook = new Workbook(); //工作簿
             Worksheet sheet = workbook.Worksheets[0]; //工作表
             workbook.Worksheets[0].Name = "排考表";

             #region 样式 已注释
             //Cells cells = sheet.Cells;//单元格
             ////样式2
             //Aspose.Cells.Style style2 = workbook.Styles[workbook.Styles.Add()];//新增样式
             //style2.HorizontalAlignment = TextAlignmentType.Center;//文字居中
             //style2.VerticalAlignment = TextAlignmentType.Center;
             //style2.Font.Name = "宋体";//文字字体
             //style2.Font.Size = 12;//文字大小
             //style2.Font.IsBold = true;//粗体
             //style2.BackgroundColor = System.Drawing.Color.Yellow;
             //style2.IsTextWrapped = true;//单元格内容自动换行
             //style2.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
             //style2.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
             //style2.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
             //style2.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
             //cells.SetRowHeight(3, 10);//设高
             //cells.SetColumnWidth(1, 50);//设宽
             //cells[0, 2].PutValue("样式使用");
             //cells[0, 2].SetStyle(style2); //0表示行号,2表示列号
             //cells.Merge(1, 2, 3, 4);//合并单元格  1表示行号,2表示列号,3表示合并的行号,4表示合并的列数; 把3或者4其中一个改变成1 ,表示不合并行或者列;如cells.Merge(1, 2, 3, 1);只合并三行,不合并列
             #endregion

             List<string> headName = new List<string> { "col1", "col2", "col3", "col4", "col5" };

             //动态生成excel  利用apose.cells
             for(int i=0;i<headName.Count;i++)
             {
                 sheet.Cells[0, i].PutValue(headName[i]);
             }

             for (int i = 0; i < GridView2.Rows.Count; i++)
             {
                 for(int j=0;j<GridView2.Rows[i].Cells.Count;j++)
                 {
                     sheet.Cells[i + 1, j].PutValue(GridView2.Rows[i].Cells[j].Text);
                 }
             }

             #region   先保存 本地本件,再下载,已注释
             //string filename = Server.MapPath(Guid.NewGuid().ToString() + ".xls");
             //workbook.Save(filename);

             ////以字符流的形式下载文件
             //FileStream fs = new FileStream(filename, FileMode.Open);
             //byte[] bytes1 = new byte[(int)fs.Length];
             //fs.Read(bytes1, 0, bytes1.Length);
             //fs.Close();
             #endregion

             Response.ContentType = "application/octet-stream";
             //通知浏览器下载文件而不是打开
             Response.AddHeader("Content-Disposition", "attachment;  filename=" + HttpUtility.UrlEncode("zxc.xls", System.Text.Encoding.UTF8));
               //  Response.BinaryWrite(bytes1);
             Response.BinaryWrite(workbook.SaveToStream().ToArray());
             Response.Flush();
             Response.End();
        }
开发者ID:polei,项目名称:Excel----,代码行数:63,代码来源:aposeCell.aspx.cs

示例9: downloadModel_Click

        //导出模板
        protected void downloadModel_Click(object sender, EventArgs e)
        {
            Workbook workbook = new Workbook(); //工作簿
            Worksheet sheet = workbook.Worksheets[0]; //工作表
            workbook.Worksheets[0].Name = "排考表";

            #region 样式 已注释
            //Cells cells = sheet.Cells;//单元格
            ////样式2
            //Aspose.Cells.Style style2 = workbook.Styles[workbook.Styles.Add()];//新增样式
            //style2.HorizontalAlignment = TextAlignmentType.Center;//文字居中
            //style2.VerticalAlignment = TextAlignmentType.Center;
            //style2.Font.Name = "宋体";//文字字体
            //style2.Font.Size = 12;//文字大小
            //style2.Font.IsBold = true;//粗体
            //style2.BackgroundColor = System.Drawing.Color.Yellow;
            //style2.IsTextWrapped = true;//单元格内容自动换行
            //style2.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
            //style2.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
            //style2.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
            //style2.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
            //cells.SetRowHeight(3, 10);//设高
            //cells.SetColumnWidth(1, 50);//设宽
            //cells[0, 2].PutValue("样式使用");
            //cells[0, 2].SetStyle(style2); //0表示行号,2表示列号
            //cells.Merge(1, 2, 3, 4);//合并单元格  1表示行号,2表示列号,3表示合并的行号,4表示合并的列数; 把3或者4其中一个改变成1 ,表示不合并行或者列;如cells.Merge(1, 2, 3, 1);只合并三行,不合并列
            #endregion

            // Get the first worksheet.
            Worksheet worksheet1 = workbook.Worksheets[0];
            // Add a new worksheet and access it.

            // Get the validations collection.
            ValidationCollection validations = worksheet1.Validations;
            // Create a new validation to the validations list.
            Validation validation = validations[validations.Add()];
            // Set the validation type.
            validation.Type = Aspose.Cells.ValidationType.List;
            // Set the operator.
            validation.Operator = OperatorType.None;
            // Set the in cell drop down.
            validation.InCellDropDown = true;
            // Set the formula1.
            validation.Formula1 = string.Join(",",new string[] { "102教室", "202教室" } );
            // Enable it to show error.
            validation.ShowError = true;
            // Set the alert type severity level.
            validation.AlertStyle = ValidationAlertType.Stop;
            // Set the error title.
            validation.ErrorTitle = "请选择正确的班级";
            // Set the error message.
            validation.ErrorMessage = "班级不存在于下拉框中!";
            // Specify the validation area.
            CellArea area;
            area.StartRow = 0;
            area.EndRow = 4;
            area.StartColumn = 0;
            area.EndColumn = 0;
            // Add the validation area.
            validation.AreaList.Add(area);
            // Save the Excel file.
             //   workbook.Save("d:\\test\\validationtypelist.xls");

            Response.ContentType = "application/octet-stream";
            //通知浏览器下载文件而不是打开
            Response.AddHeader("Content-Disposition", "attachment;  filename=" + HttpUtility.UrlEncode("zxc.xls", System.Text.Encoding.UTF8));
            Response.BinaryWrite(workbook.SaveToStream().ToArray());
            Response.Flush();
            Response.End();
        }
开发者ID:polei,项目名称:Excel----,代码行数:71,代码来源:aposeCell.aspx.cs

示例10: Caculate

        private void Caculate(Condtions condtions)
        {
            this.bw.ReportProgress(0, string.Format("正在准备数据..."));

            DataTable dtTimeLagRange = condtions.TimelagRange;
            DataTable dtTimeScaleRange = condtions.TimescaleRange;
            List<int> listTimeLag = GetRangeList(dtTimeLagRange);
            List<int> listTimeScale = GetRangeList(dtTimeScaleRange);
            string sConStr = string.Format(this.sConnectionString, condtions.MDBPath);
            OleDbDataAdapter dbAdapter1 = new OleDbDataAdapter(this.sSQLGetZD, sConStr);
            DataTable dtSiteLocation = new DataTable();
            dbAdapter1.Fill(dtSiteLocation);
            OleDbDataAdapter dbAdapter2 = new OleDbDataAdapter(this.sSQLGetZDValue, sConStr);
            DataTable dtSiteSeries = new DataTable();
            dbAdapter2.Fill(dtSiteSeries);

            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];
            Cells cells = sheet.Cells;

            this.bw.ReportProgress(0, string.Format("正在计算..."));
            double[,] SpatialWeightMatrix = DTSTI.GetSpatialWeightMatrix(dtSiteLocation, condtions.Type, condtions.Lambda);
            double[] OriginalSpatioTemporalSeries = DTSTI.GetOriginalSpatioTemporalSeries(dtSiteSeries);
            double[] IntegratedOriginalSpatioTemporalSeries = DTSTI.GetIntegratedSeries(OriginalSpatioTemporalSeries);

            int iRow = 1;
            for (int i = 0; i < listTimeScale.Count; i++)
            {
                int iTimeScale = listTimeScale[i];

                cells[iRow, 0].PutValue(iTimeScale);
                int iColumn = 1;

                for (int j = 0; j < listTimeLag.Count; j++)
                {
                    int iTimeLag = listTimeLag[j];
                    cells[0, iColumn].PutValue(iTimeLag);

                    double[,] TemporalWeightMatrix = DTSTI.GetTemporalWeightMatrix(dtSiteSeries.Rows.Count / dtSiteLocation.Rows.Count, iTimeLag);
                    double[] LaggedSpatioTemporalSeries = DTSTI.GetLaggedSpatioTemporalSeries(OriginalSpatioTemporalSeries, SpatialWeightMatrix, TemporalWeightMatrix);
                    double[] IntegratedLaggedSpatioTemporalSeries = DTSTI.GetIntegratedSeries(LaggedSpatioTemporalSeries);
                    double DTSTIValue = DTSTI.GetDetrend(IntegratedOriginalSpatioTemporalSeries, IntegratedLaggedSpatioTemporalSeries, iTimeScale);
                    this.bw.ReportProgress(0, string.Format("TimeScale:{1},TimeLag:{0},DTSTI:{2}", iTimeLag, iTimeScale, DTSTIValue));
                    cells[iRow, iColumn].PutValue(DTSTIValue);
                    iColumn++;
                }
                iRow++;
            }
            System.IO.MemoryStream ms = workbook.SaveToStream();
            byte[] bt = ms.ToArray();
            string sOutPath = Path.Combine(condtions.OutputFolder, string.Format("{0}(Lambda={1}).xls", (condtions.Type == SpatialMatrixType.Complete ? "Complete" : "Mixtrue"), condtions.Lambda));
            workbook.Save(sOutPath);
        }
开发者ID:bingotao,项目名称:IndexCalculate,代码行数:53,代码来源:IndexCalculate.cs

示例11: ToExcel

        ///// <summary>
        ///// 导出Excel
        ///// </summary>
        ///// <param name="table">数据源</param>
        ///// <param name="outName">输出EXCEL名称</param>
        //public static byte[] ToExcel(DataTable table)
        //{
        //    string outName = table.TableName;
        //    Workbook workBook = new Workbook();
        //    workBook.Worksheets.Clear();
        //    workBook.Worksheets.Add(outName);//New Worksheet是Worksheet的name
        //    Worksheet ws = workBook.Worksheets[0];
        //    //Style style = workBook.Styles[workBook.Styles.Add()];
        //    ////Setting the line style of the top border
        //    //style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thick;
        //    ////Setting the color of the top border
        //    //style.Borders[BorderType.TopBorder].Color =  Color.Black;
        //    ////Setting the line style of the bottom border
        //    //style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thick;
        //    ////Setting the color of the bottom border
        //    //style.Borders[BorderType.BottomBorder].Color = Color.Black;
        //    ////Setting the line style of the left border
        //    //style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thick;
        //    ////Setting the color of the left border
        //    //style.Borders[BorderType.LeftBorder].Color = Color.Black;
        //    ////Setting the line style of the right border
        //    //style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thick;
        //    ////Setting the color of the right border
        //    //style.Borders[BorderType.RightBorder].Color = Color.Black;
        //    int x = 1;
        //    for (int i = 0; i < table.Rows.Count; i++)
        //    {
        //        if (i != 0)
        //            x++;
        //        for (int j = 0; j < table.Columns.Count; j++)
        //        {
        //            if (i == 0)
        //            {
        //                ws.Cells[x - 1, j].PutValue(table.Columns[j].Caption);
        //                //ws.Cells[x - 1, j].SetStyle(style);
        //            }
        //            ws.Cells[x, j].PutValue(table.Rows[i][j].ToString());
        //            //ws.Cells[x, j].SetStyle(style);
        //        }
        //    }
        //    workBook.Worksheets[0].AutoFitColumns();
        //    System.IO.MemoryStream ms = workBook.SaveToStream();//生成数据流
        //    byte[] bt = ms.ToArray();
        //    return bt;
        //    //WorkbookDesigner designer = new WorkbookDesigner();
        //    //designer.Workbook = workBook;
        //    //designer.Process();
        //    ////将流文件写到客户端流的形式写到客户端,名称是outName.xls
        //    //designer.Save(string.Format("{0}.xls",outName), SaveType.OpenInExcel, FileFormatType.Excel2003, System.Web.HttpContext.Current.Response);
        //    ////Response.Flush();
        //    ////Response.Close();
        //    //designer = null;
        //    //// Response.End();
        //    ////return View("getexcel");
        //}
        /// <summary>
        /// 导出Excel
        /// </summary>
        /// <param name="table">数据源</param>
        /// <param name="outName">输出EXCEL名称</param>
        public static byte[] ToExcel(DataTable table)
        {
            string outName = table.TableName;
            Workbook workBook = new Workbook();
            workBook.Worksheets.Clear();
            workBook.Worksheets.Add();//outName);//New Worksheet是Worksheet的name
            Worksheet ws = workBook.Worksheets[0];

            for (int j = 0; j < table.Columns.Count - 1; j++)
            {
                ws.Cells[1, j].PutValue(table.Columns[j].Caption);
            }

            int x = 1;
            for (int i = 0; i < table.Rows.Count - 1; i++)
            {
                if (i != 0)
                    x++;

                for (int j = 0; j < table.Columns.Count; j++)
                {
                    if (i == 0)
                    {
                        ws.Cells[x - 1, j].PutValue(table.Columns[j].Caption);
                        //ws.Cells[x - 1, j].SetStyle(style);
                    }
                    ws.Cells[x, j].PutValue(table.Rows[i][j].ToString());
                    //ws.Cells[x, j].SetStyle(style);
                }
            }
            workBook.Worksheets[0].AutoFitColumns();

            System.IO.MemoryStream ms = workBook.SaveToStream();//生成数据流
            byte[] bt = ms.ToArray();
            return bt;
//.........这里部分代码省略.........
开发者ID:GreatChuangSoftWare,项目名称:WuGU,代码行数:101,代码来源:Data2Excel.cs

示例12: ToHtml

        public static byte[] ToHtml(IEnumerable<object> Items, List<SoftProjectAreaEntity> DynReportDefineDetails, int posTotal = 1)
        {
            string outName = "";// table.TableName;
            Workbook workBook = new Workbook();
            workBook.Worksheets.Clear();
            workBook.Worksheets.Add(outName);//New Worksheet是Worksheet的name
            Worksheet ws = workBook.Worksheets[0];

            int x = 0;
            var count = Items.Count();
            if (posTotal == 0)//开始处
            {
                if (count > 0)
                {
                    var item = Items.Last();//[count - 1];
                    Type type = item.GetType();
                    WriteRow(DynReportDefineDetails, ws, x, item, type);
                    x++;
                }
            }
            //写入表头
            for (var j = 0; j < DynReportDefineDetails.Count; j++)
            {
                ws.Cells[x, j].PutValue(DynReportDefineDetails[j].NameCn);
            }
            x++;

            foreach (var item in Items)
            {
                Type type = item.GetType();
                WriteRow(DynReportDefineDetails, ws, x, item, type);
                if (posTotal == 0 && x == count)
                    break;
                x++;
            }
            workBook.Worksheets[0].AutoFitColumns();

            System.IO.MemoryStream ms = workBook.SaveToStream();//生成数据流
            byte[] bt = ms.ToArray();
            return bt;
        }
开发者ID:GreatChuangSoftWare,项目名称:WuGU,代码行数:41,代码来源:Data2Excel.cs


注:本文中的Workbook.SaveToStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。