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


C# Workbook.Save方法代码示例

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


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

示例1: CreateStaticReport

    public void CreateStaticReport()
    {
        //Open template
        string path = System.Web.HttpContext.Current.Server.MapPath("~");
        path = path.Substring(0, path.LastIndexOf("\\"));
        path += @"\designer\book1.xls";

        Workbook workbook = new Workbook(path);

        Worksheet worksheet = workbook.Worksheets[0];
        //Set the orientation
        worksheet.PageSetup.Orientation = PageOrientationType.Landscape;

        //You can either choose FitToPages or Zoom property but not both at the same time
        worksheet.PageSetup.Zoom = 10;
        //Set the paper size
        worksheet.PageSetup.PaperSize = PaperSizeType.PaperA4;
        //Set the print quality of the worksheet
        worksheet.PageSetup.PrintQuality = 200;
        //Set the first page number of the worksheet pages
        worksheet.PageSetup.FirstPageNumber = 1;

        if (ddlFileVersion.SelectedItem.Value == "XLS")
        {
            ////Save file and send to client browser using selected format
            workbook.Save(HttpContext.Current.Response, "SettingPageOption.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
        }
        else
        {
            workbook.Save(HttpContext.Current.Response, "SettingPageOption.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
        }

        //end response to avoid unneeded html
        HttpContext.Current.Response.End();
    }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:35,代码来源:setting-page-option.aspx.cs

示例2: CreateStaticReport

    public void CreateStaticReport()
    {
        Workbook workbook = new Workbook();
        Worksheet sheet = workbook.Worksheets[0];

        Cells cells = sheet.Cells;

        cells["B1"].PutValue("Aspose.Cells");
        //Get Style Object
        Aspose.Cells.Style style = cells["B1"].GetStyle();

        style.RotationAngle = 45;
        style.Font.IsBold = true;
        cells["B1"].SetStyle(style);

        //Auto row fit
        sheet.AutoFitRow(0);
        //Auto column fit
        sheet.AutoFitColumn(1);

        if (ddlFileVersion.SelectedItem.Value == "XLS")
        {
            ////Save file and send to client browser using selected format
            workbook.Save(HttpContext.Current.Response, "AutoFitRowsAndColumns.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
        }
        else
        {
            workbook.Save(HttpContext.Current.Response, "AutoFitRowsAndColumns.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
        }

        //end response to avoid unneeded html
        HttpContext.Current.Response.End();
    }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:33,代码来源:auto-fit-rows-and-columns.aspx.cs

示例3: CreateStaticReport

    public void CreateStaticReport()
    {
        // Create a workbook object.
        Workbook workbook = new Workbook();

        // Create a worksheet and get the first worksheet.
        Worksheet ExcelWorkSheet = workbook.Worksheets[0];

        // Obtain the existing Validations collection.
        ValidationCollection validations = ExcelWorkSheet.Validations;

        // Create a validation object adding to the collection list.
        Validation validation = validations[validations.Add()];

        // Set the validation type.
        validation.Type = ValidationType.Decimal;

        // Specify the operator.
        validation.Operator = OperatorType.Between;

        // Set the lower and upper limits.
        validation.Formula1 = Decimal.MinValue.ToString();

        validation.Formula2 = Decimal.MaxValue.ToString();

        // Set the error message.
        validation.ErrorMessage = "Please enter a valid integer or decimal number";

        // Specify the validation area of cells.
        CellArea area;
        area.StartRow = 0;
        area.EndRow = 9;
        area.StartColumn = 0;
        area.EndColumn = 0;

        // Add the area.
        validation.AreaList.Add(area);

        // Set the number formats to 2 decimal places for the validation area.

        for (int i = 0; i < 10; i++)
        {
            Aspose.Cells.Style style = new Aspose.Cells.Style();
            style.Custom = "0.00";
           ExcelWorkSheet.Cells[i, 0].SetStyle(style);
        }

        if (ddlFileVersion.SelectedItem.Value == "XLS")
        {
            ////Save file and send to client browser using selected format
            workbook.Save(HttpContext.Current.Response, "DecimalNumberValidation.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
        }
        else
        {
            workbook.Save(HttpContext.Current.Response, "DecimalNumberValidation.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
        }

        //end response to avoid unneeded html
        HttpContext.Current.Response.End();
    }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:60,代码来源:decimal-number-validation.aspx.cs

示例4: CreateStaticReport

    public void CreateStaticReport()
    {
        //Create a new workbook
        Workbook workbook = new Workbook();

        //Adding a Name for non sequenced range
        int index = workbook.Worksheets.Names.Add("NonSequencedRange");

        Name name = workbook.Worksheets.Names[index];

        //Creating a non sequence range of cells
        name.RefersTo = "=Sheet1!$A$1:$B$3,Sheet1!$D$5:$E$6";

        if (ddlFileVersion.SelectedItem.Value == "XLS")
        {
            ////Save file and send to client browser using selected format
            workbook.Save(HttpContext.Current.Response, "NonSequencedRange.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
        }
        else
        {
            workbook.Save(HttpContext.Current.Response, "NonSequencedRange.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
        }

        //end response to avoid unneeded html
        HttpContext.Current.Response.End();
    }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:26,代码来源:non-sequenced-named-ranges.aspx.cs

示例5: CreateStaticReport

    public void CreateStaticReport()
    {
        //Open template
        string path = System.Web.HttpContext.Current.Server.MapPath("~");
        path = path.Substring(0, path.LastIndexOf("\\"));
        path += @"\designer\Workbooks\NumberFormatting.xls";

        //Create a new workbook
        Workbook workbook = new Workbook(path);

        //Get the cells collection in the workbook
        Cells cells = workbook.Worksheets[0].Cells;

        Aspose.Cells.Style style;

        //Set number format with built-in index
        for (int i = 1; i < 37; i++)
        {
            cells[i, 1].PutValue(1234.5);

            int Number = cells[i, 0].IntValue;

            //Get Style of Cell
            style = cells[i, 1].GetStyle();

            //Set the display number format
            style.Number = Number;

            //Apply Style
            cells[i, 1].SetStyle(style);
        }

        //Set number format with custom format string
        for (int i = 1; i < 4; i++)
        {
            cells[i, 3].PutValue(1234.5);

            //Get Style of Cell
            style = cells[i, 3].GetStyle();

            //Set the display custom number format
            style.Custom = cells[i, 2].StringValue;

            //Apply Style
            cells[i, 3].SetStyle(style);
        }

        if (ddlFileVersion.SelectedItem.Value == "XLS")
        {
            ////Save file and send to client browser using selected format
            workbook.Save(HttpContext.Current.Response, "NumberFormatting.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
        }
        else
        {
            workbook.Save(HttpContext.Current.Response, "NumberFormatting.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
        }

        //end response to avoid unneeded html
        HttpContext.Current.Response.End();
    }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:60,代码来源:number-formatting.aspx.cs

示例6: CreateStaticReport

    public void CreateStaticReport()
    {
        //Open template
        string path = System.Web.HttpContext.Current.Server.MapPath("~");
        path = path.Substring(0, path.LastIndexOf("\\"));
        path += @"\designer\Workbooks\ProtectingWorksheet.xls";

        //Instantiate a workbook
        Workbook workbook = new Workbook(path);

        //Get the first worksheet of the workbook
        Worksheet worksheet = workbook.Worksheets[0];
        //If the worksheet is protected, unprotect it
        if (worksheet.IsProtected)
            worksheet.Unprotect();

        if (ddlFileVersion.SelectedItem.Value == "XLS")
        {
            ////Save file and send to client browser using selected format
            workbook.Save(HttpContext.Current.Response, "UnprotectWorksheet.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
        }
        else
        {
            workbook.Save(HttpContext.Current.Response, "UnprotectWorksheet.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
        }

        //end response to avoid unneeded html
        HttpContext.Current.Response.End();
    }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:29,代码来源:unprotect-a-worksheet.aspx.cs

示例7: Run

        public static void Run()
        {
            // ExStart:SaveODSFileinODF11and12Specifications
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create workbook
            Workbook workbook = new Workbook();

            // Access first worksheet
            Worksheet worksheet = workbook.Worksheets[0];

            // Put some value in cell A1
            Cell cell = worksheet.Cells["A1"];
            cell.PutValue("Welcome to Aspose!");

            // Save ODS in ODF 1.2 version which is default
            OdsSaveOptions options = new OdsSaveOptions();
            workbook.Save(dataDir + "ODF1.2_out.ods", options);

            // Save ODS in ODF 1.1 version
            options.IsStrictSchema11 = true;
            workbook.Save(dataDir + "ODF1.1_out.ods", options);
            // ExEnd:SaveODSFileinODF11and12Specifications
        }
开发者ID:aspose-cells,项目名称:Aspose.Cells-for-.NET,代码行数:25,代码来源:OdsFileSaveOptions.cs

示例8: CreateStaticReport

    protected void CreateStaticReport()
    {
        //Instantiate a new workbook
        Workbook workbook = new Workbook();

        //Set default font
        Aspose.Cells.Style style = workbook.DefaultStyle;
        style.Font.Name = "Tahoma";
        workbook.DefaultStyle = style;

        //Call Method to create data
        CreateSaticData(workbook);

        //Call Method to find data
        FindData(workbook);

        if (ddlFileVersion.SelectedItem.Value == "XLS")
        {
            ////Save file and send to client browser using selected format
            workbook.Save(HttpContext.Current.Response, "FindOrSearchData.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
        }
        else
        {
            workbook.Save(HttpContext.Current.Response, "FindOrSearchData.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
        }

        //end response to avoid unneeded html
        HttpContext.Current.Response.End();
    }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:29,代码来源:find-or-search-data.aspx.cs

示例9: CreateStaticReport

    public void CreateStaticReport()
    {
        //Open template
        string path = System.Web.HttpContext.Current.Server.MapPath("~");
        path = path.Substring(0, path.LastIndexOf("\\"));
        path += @"\designer\book1.xls";

        //Instantiate a Workbook object by calling its empty constructor
        Workbook workbook = new Workbook(path);

        //Retrieve a list of all custom document properties of the Excel file
        CustomDocumentPropertyCollection customProperties = workbook.Worksheets.CustomDocumentProperties;

        //Adding a custom document property to the Excel file
        DocumentProperty publisher = customProperties.Add("Publisher", "Aspose");

        if (ddlFileVersion.SelectedItem.Value == "XLS")
        {
            ////Save file and send to client browser using selected format
            workbook.Save(HttpContext.Current.Response, "CustomDocumentProperties.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
        }
        else
        {
            workbook.Save(HttpContext.Current.Response, "CustomDocumentProperties.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
        }

        //end response to avoid unneeded html
        HttpContext.Current.Response.End();
    }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:29,代码来源:adding-document-properties.aspx.cs

示例10: CreateStaticReport

    public void CreateStaticReport()
    {
        //initialize the workbook object
        Workbook workbook = new Workbook();

        //Get first worksheet in the workbook
        Worksheet sheet = workbook.Worksheets[0];

        //Apply WordArt Style with font settings
        sheet.Shapes.AddTextEffect(Aspose.Cells.Drawing.MsoPresetTextEffect.TextEffect1, "Aspose.Cells for .NET", "Arial", 15, true, true, 5, 5, 2, 2, 100, 175);

        //Apply WordArt Style with font settings
        sheet.Shapes.AddTextEffect(Aspose.Cells.Drawing.MsoPresetTextEffect.TextEffect2, "Aspose.Cells for Java", "Verdana", 30, true, false, 10, 5, 2, 2, 100, 100);

        //Apply WordArt Style with font settings
        sheet.Shapes.AddTextEffect(Aspose.Cells.Drawing.MsoPresetTextEffect.TextEffect3, "Aspose.Cells for Reporting Services", "Times New Roman", 25, false, true, 15, 5, 2, 2, 100, 150);

        if (ddlFileVersion.SelectedItem.Value == "XLS")
        {
            ////Save file and send to client browser using selected format
            workbook.Save(HttpContext.Current.Response, "AddingWordArt.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
        }
        else
        {
            workbook.Save(HttpContext.Current.Response, "AddingWordArt.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
        }

        //end response to avoid unneeded html
        HttpContext.Current.Response.End();
    }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:30,代码来源:adding-wordart.aspx.cs

示例11: Button1_Click

        private void Button1_Click(object sender, System.EventArgs e)
        {
            //Create a new workbook
            Workbook workbook = new Workbook();

            //Add an Extra worksheet
            workbook.Worksheets.Add();

            //Get the first worksheet in the workbook
            Worksheet sheet = workbook.Worksheets[0];

            //Display the first worksheet of the Excel file
            sheet.IsVisible = true;

            if (ddlFileVersion.SelectedItem.Value == "XLS")
            {
                ////Save file and send to client browser using selected format
                workbook.Save(HttpContext.Current.Response, "DisplayWorksheet.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
            }
            else
            {
                workbook.Save(HttpContext.Current.Response, "DisplayWorksheet.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
            }

            //end response to avoid unneeded html
            HttpContext.Current.Response.End();
        }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:27,代码来源:display-hide-worksheet.aspx.cs

示例12: Run

        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create workbook
            Workbook wb = new Workbook();
            Cells cells = wb.Worksheets[0].Cells;

            // Set formula
            Cell cell = cells[0, 0];
            cell.SetArrayFormula("=MYFUNC()", 2, 2);

            Style style = cell.GetStyle();
            style.Number = 14;
            cell.SetStyle(style);

            // Set calculation options for formula
            CalculationOptions copt = new CalculationOptions();
            copt.CustomFunction = new CustomFunctionStaticValue();
            wb.CalculateFormula(copt);

            // Save to xlsx by setting the calc mode to manual
            wb.Settings.CalcMode = CalcModeType.Manual;
            wb.Save(dataDir + "output_out.xlsx");

            // Save to pdf
            wb.Save(dataDir + "output_out.pdf");
            // ExEnd:1
        }
开发者ID:aspose-cells,项目名称:Aspose.Cells-for-.NET,代码行数:31,代码来源:ReturnRangeOfValuesUsingICustomFunction.cs

示例13: CreateStaticReport

    public void CreateStaticReport()
    {
        //Open template
        string path = System.Web.HttpContext.Current.Server.MapPath("~");
        path = path.Substring(0, path.LastIndexOf("\\"));
        path += @"\designer\book1.xls";

        Workbook workbook = new Workbook(path);

        Worksheet worksheet = workbook.Worksheets[0];
        worksheet.PageSetup.SetFooter(0, "&T");

        worksheet.PageSetup.SetHeader(1, "&D");

        if (ddlFileVersion.SelectedItem.Value == "XLS")
        {
            ////Save file and send to client browser using selected format
            workbook.Save(HttpContext.Current.Response, "HeadersAndFooters.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
        }
        else
        {
            workbook.Save(HttpContext.Current.Response, "HeadersAndFooters.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
        }

        //end response to avoid unneeded html
        HttpContext.Current.Response.End();
    }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:27,代码来源:headers-and-footers.aspx.cs

示例14: Main

        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Instantiate a new Workbook.
            Workbook workbook = new Workbook();

            //Get the first worksheet.
            Worksheet sheet = workbook.Worksheets[0];

            //Define a string variable to store the image path.
            string ImageUrl = dataDir+ "aspose-logo.jpg";

            //Get the picture into the streams.
            FileStream fs = File.OpenRead(ImageUrl);

            //Define a byte array.
            byte[] imageData = new Byte[fs.Length];

            //Obtain the picture into the array of bytes from streams.
            fs.Read(imageData, 0, imageData.Length);

            //Close the stream.
            fs.Close();

            //Set the background image for the sheet.
            sheet.SetBackground(imageData);

            //Save the Excel file
            workbook.Save(dataDir+ "BackImageSheet.out.xlsx");

            //Save the HTML file
            workbook.Save(dataDir+ "BackImageSheet1.out.html", SaveFormat.Html);
        }
开发者ID:nesterenes,项目名称:Aspose_Cells_NET,代码行数:35,代码来源:SetBackgroundPicture.cs

示例15: CreateStaticReport

    public void CreateStaticReport()
    {
        //Open template.
        string path = System.Web.HttpContext.Current.Server.MapPath("~");
        path = path.Substring(0, path.LastIndexOf("\\"));
        path += @"\designer\book1.xls";

        //Instantiate a new Workbook object.
        Workbook workbook = new Workbook(path);

        //Specify Strong Encryption type (RC4,Microsoft Strong Cryptographic Provider).
        workbook.SetEncryptionOptions(EncryptionType.StrongCryptographicProvider, 128);

        //Use this line if you want to specify XOR Encrytion type.
        //workbook.SetEncryptionOptions(EncryptionType.XOR, 40);

        //Password protect the file.
        workbook.Settings.Password = "007";

        if (ddlFileVersion.SelectedItem.Value == "XLS")
        {
            ////Save file and send to client browser using selected format
            workbook.Save(HttpContext.Current.Response, "EncryptedBook.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
        }
        else
        {
            workbook.Save(HttpContext.Current.Response, "EncryptedBook.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
        }

        //end response to avoid unneeded html
        HttpContext.Current.Response.End();
    }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:32,代码来源:encrypt-an-excel-file.aspx.cs


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