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


C# Workbook类代码示例

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


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

示例1: Run

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

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);
            if (!IsExists)
                System.IO.Directory.CreateDirectory(dataDir);

            // Instantiating a Workbook object
            Workbook workbook = new Workbook();

            // Obtaining the reference of the worksheet
            Worksheet worksheet = workbook.Worksheets[0];

            // Accessing the "A1" cell from the worksheet
            Aspose.Cells.Cell cell = worksheet.Cells["A1"];

            // Adding some value to the "A1" cell
            cell.PutValue("Visit Aspose!");

            // Merging the first three columns in the first row to create a single cell
            worksheet.Cells.Merge(0, 0, 1, 3);


            // Saving the Excel file
            workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003);
            // ExEnd:1
        }
开发者ID:aspose-cells,项目名称:Aspose.Cells-for-.NET,代码行数:31,代码来源:MergingCells.cs

示例2: Borders

        public void Borders()
        {
            var border = new CellBorder();
            border.Left = new BorderEdge { Style = BorderStyle.Double, Color = Color.Black }; //apply double black border to left edge
            border.All = new BorderEdge { Style = BorderStyle.Medium, Color = Color.Black }; //apply medium black border to left, right, top and bottom edge
            border.Diagonal = new BorderEdge { Style = BorderStyle.Dashed, Color = Color.Black }; // diagonal border is supported also
            border.DiagonalUp = true; //in this case you should set which diagonal to use
            border.DiagonalDown = false; //in this case you should set which diagonal to use

            var wb = new Workbook();
            var sheet = wb.Sheets.AddSheet("Demo Sheet");
            sheet["A1"].Style.Border = border; //apply prepared border to cell A1
            sheet["B1"].Style.Border = border; //apply prepared border to cell B1
            sheet["C1"].Style.Border = border; //apply prepared border to cell C1
            sheet["C1"].Style.Border.Bottom = null; //watch out, you have removed bottom border on A1, A2 and A3

            var range = sheet["A3", "E10"];

            range.SetBorder(new BorderEdge { Style = BorderStyle.Thin, Color = Color.Black }); //border is easier to set on ranges

            range.GetRow(0).SetOutsideBorder(new BorderEdge { Style = BorderStyle.Medium, Color = Color.Black }); //header may need a heavier border

            range.SetOutsideBorder(new BorderEdge { Style = BorderStyle.Double, Color = Color.Black }); //use double border outside the table

            wb.Save("Borders.xlsx");
        }
开发者ID:ronakshah725,项目名称:xlio,代码行数:26,代码来源:Styles.cs

示例3: Run

        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            // Open a template Excel file
            Workbook workbook = new Workbook(dataDir+ "book1.xlsx");

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

            // Get the A1 cell
            Cell cell = sheet.Cells["A1"];

            // Get the conditional formatting result object
            ConditionalFormattingResult cfr = cell.GetConditionalFormattingResult();

            // Get the icon set
            ConditionalFormattingIcon icon = cfr.ConditionalFormattingIcon;

            // Create the image file based on the icon's image data
            File.WriteAllBytes(dataDir+ "imgIcon.out.jpg", icon.ImageData);
            // ExEnd:1
            
        }
开发者ID:aspose-cells,项目名称:Aspose.Cells-for-.NET,代码行数:25,代码来源:GetIconSetsDataBars.cs

示例4: PipeComponentImporter

        public PipeComponentImporter(Workbook workbook, Dictionary<Int32, List<CellValue>> pipeComponentCellValuesToCheck,
                                     string tagNumberCellName, string lineNumberCellName, string pandIDCellName)
        {
            mTagNumberCellName = tagNumberCellName;
            mLineNumberCellName = lineNumberCellName;
            mPandIDCellName = pandIDCellName;

            mCee = new CmsEquipmentEntities();
            mWorkbook = workbook;
            mPipeComponentCellValuesToCheck = pipeComponentCellValuesToCheck;

            mExistingPipes = mCee.Pipes
                .Include("Area")
                .Include("PipeClass")
                .Include("PipeSize")
                .Include("PipeFluidCode")
                .Include("PipeCategory")
                .Include("PipeSpecialFeature").ToList();

            mImportResult = mCee.PipeComponents
                .Include("Pipe")
                .Include("Pipe.Area")
                .Include("PipeComponentType").ToList();

            mDocumentTypes = mCee.DocumentTypes.ToList();
            mExistingPipeComponentTypes = mCee.PipeComponentTypes.ToList();

            mExistingPipeComponentProperties = mCee.PipeComponentProperties.ToList();
            mDrawings = (from x in mDocumentTypes where x.Name == "Drawing" select x.Documents).FirstOrDefault().ToList();
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:30,代码来源:PipeComponentImporter.cs

示例5: 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

示例6: Run

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

            // Create workbook from source Excel file
            Workbook workbook = new Workbook(dataDir + "Book1.xlsx");

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

            // Get the Cells collection in the first worksheet
            Cells cells = worksheet.Cells;

            // Create a cellarea i.e.., A2:B11
            CellArea ca = CellArea.CreateCellArea("A2", "B11");

            // Apply subtotal, the consolidation function is Sum and it will applied to Second column (B) in the list
            cells.Subtotal(ca, 0, ConsolidationFunction.Sum, new int[] { 1 }, true, false, true);

            // Set the direction of outline summary
            worksheet.Outline.SummaryRowBelow = true;

            // Save the excel file
            workbook.Save(dataDir + "output_out.xlsx");
            // ExEnd:1
        }
开发者ID:aspose-cells,项目名称:Aspose.Cells-for-.NET,代码行数:28,代码来源:ApplyingSubtotalChangeSummaryDirection.cs

示例7: BTN_Replace_Click

 private void BTN_Replace_Click(object sender, EventArgs e)
 {
     if (TXBX_Find.Text != "" && TXBX_Replace.Text!="")
     {
         workbook = new Workbook(FOD_OpenFile.FileName);
         FindOptions Opts = new FindOptions();
         Opts.LookInType = LookInType.Values;
         Opts.LookAtType = LookAtType.Contains;
         string found = "";
         Cell cell = null;
         foreach (Worksheet sheet in workbook.Worksheets)
         {
             do
             {
                 cell = sheet.Cells.Find(TXBX_Find.Text, cell, Opts);
                 if (cell != null)
                 {
                     string celltext = cell.Value.ToString();
                     celltext = celltext.Replace(TXBX_Find.Text, TXBX_Replace.Text);
                     cell.PutValue(celltext);
                 }
             }
             while (cell != null);
         }
         LBL_FindResults.Text = "Replaced All Existing Values, Save the file now";
     }
 }
开发者ID:aspose-cells,项目名称:Aspose.Cells-for-.NET,代码行数:27,代码来源:Find+and+replace.cs

示例8: Main

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

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);
            if (!IsExists)
                System.IO.Directory.CreateDirectory(dataDir);

            //Instantiate a new Workbook
            Workbook workbook = new Workbook();
            //Get the first worksheet's cells collection
            Cells cells = workbook.Worksheets[0].Cells;

            //Add string values to the cells
            cells["A1"].PutValue("A1");
            cells["C10"].PutValue("C10");

            //Add a blank picture to the D1 cell
            Picture pic = workbook.Worksheets[0].Shapes.AddPicture(0, 3, 10, 6, null);

            //Specify the formula that refers to the source range of cells
            //pic.Formula = "A1:C10";

            //Update the shapes selected value in the worksheet
            workbook.Worksheets[0].Shapes.UpdateSelectedValue();

            //Save the Excel file.
            workbook.Save(dataDir + "output.out.xls");
        }
开发者ID:nesterenes,项目名称:Aspose_Cells_NET,代码行数:31,代码来源:PictureCellReference.cs

示例9: Run

        public static void Run()
        {
            // ExStart:DeterminingLicenseLoading
            // The path to the License File
            string licPath = @"Aspose.Cells.lic";

            // Create workbook object before setting a license
            Workbook workbook = new Workbook();

            // Check if the license is loaded or not. It will return false
            Console.WriteLine(workbook.IsLicensed);

            try
            {
                Aspose.Cells.License lic = new Aspose.Cells.License();
                lic.SetLicense(licPath);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            // Check if the license is loaded or not. Now it will return true
            Console.WriteLine(workbook.IsLicensed);
            // ExEnd:DeterminingLicenseLoading
        }
开发者ID:aspose-cells,项目名称:Aspose.Cells-for-.NET,代码行数:26,代码来源:DeterminingLicenseLoading.cs

示例10: Main

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

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);
            if (!IsExists)
                System.IO.Directory.CreateDirectory(dataDir);

            //Instantiating a Workbook object
            Workbook workbook = new Workbook();

            //Adding a new worksheet to the Excel object
            workbook.Worksheets.Add();

            //Obtaining the reference of the newly added worksheet by passing its sheet index
            Worksheet worksheet = workbook.Worksheets[0];

            //Accessing the "A1" cell from the worksheet
            Cell cell = worksheet.Cells["A1"];

            //Adding some value to the "A1" cell
            cell.PutValue("Hello");

            //Setting the font Superscript
            Style style = cell.GetStyle();
            style.Font.IsSuperscript = true;
            cell.SetStyle(style);

            //Saving the Excel file
            workbook.Save(dataDir+ "Superscript.xls", SaveFormat.Auto);
            
            
        }
开发者ID:assadvirgo,项目名称:Aspose_Cells_NET,代码行数:35,代码来源:SettingSuperscripteffect.cs

示例11: Main

        static void Main(string[] args)
        {
            string MyDir = @"Files\";
            //Instantiating a Workbook object
            Workbook workbook = new Workbook();

            //Adding a new worksheet to the Excel object
            int sheetIndex = workbook.Worksheets.Add();

            //Obtaining the reference of the newly added worksheet by passing its sheet index
            Worksheet worksheet = workbook.Worksheets[sheetIndex];

            //Adding a value to "A1" cell
            worksheet.Cells["A1"].PutValue(1);

            //Adding a value to "A2" cell
            worksheet.Cells["A2"].PutValue(2);

            //Adding a value to "A3" cell
            worksheet.Cells["A3"].PutValue(3);

            //Adding a SUM formula to "A4" cell
            worksheet.Cells["A4"].Formula = "=SUM(A1:A3)";

            //Calculating the results of formulas
            workbook.CalculateFormula();

            //Get the calculated value of the cell
            string value = worksheet.Cells["A4"].Value.ToString();

            //Saving the Excel file
            workbook.Save(MyDir + "Adding Formula.xls");
        }
开发者ID:assadvirgo,项目名称:Aspose_Cells_NET,代码行数:33,代码来源:Program.cs

示例12: Main

        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //Creating a file stream containing the Excel file to be opened
            FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open);

            //Instantiating a Workbook object
            //Opening the Excel file through the file stream
            Workbook workbook = new Workbook(fstream);

            //Adding a new worksheet to the Workbook object
            int i = workbook.Worksheets.Add();

            //Obtaining the reference of the newly added worksheet by passing its sheet index
            Worksheet worksheet = workbook.Worksheets[i];

            //Setting the name of the newly added worksheet
            worksheet.Name = "My Worksheet";

            //Saving the Excel file
            workbook.Save(dataDir + "output.xls");

            //Closing the file stream to free all resources
            fstream.Close();
        }
开发者ID:mmunchandersen,项目名称:Aspose_Cells_NET,代码行数:27,代码来源:Program.cs

示例13: Run

        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            string output1Path = dataDir + "Output.xlsx";
            string output2Path = dataDir + "Output.out.ods";

            Workbook workbook = new Workbook();
            Style style = workbook.CreateBuiltinStyle(BuiltinStyleType.Title);

            Cell cell = workbook.Worksheets[0].Cells["A1"];
            cell.PutValue("Aspose");
            cell.SetStyle(style);

            Worksheet worksheet = workbook.Worksheets[0];
            worksheet.AutoFitColumn(0);
            worksheet.AutoFitRow(0);

            workbook.Save(output1Path);
            Console.WriteLine("File saved {0}", output1Path);
            workbook.Save(output2Path);
            Console.WriteLine("File saved {0}", output1Path);
            // ExEnd:1
        }
开发者ID:aspose-cells,项目名称:Aspose.Cells-for-.NET,代码行数:25,代码来源:UsingBuiltinStyles.cs

示例14: Run

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

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);
            if (!IsExists)
                System.IO.Directory.CreateDirectory(dataDir);

            // Instantiating a Workbook object
            Workbook workbook = new Workbook();

            // Obtaining the reference of the worksheet
            Worksheet worksheet = workbook.Worksheets[0];

            // Accessing the "A1" cell from the worksheet
            Aspose.Cells.Cell cell = worksheet.Cells["A1"];

            // Adding some value to the "A1" cell
            cell.PutValue("Visit Aspose!");

            // Setting the horizontal alignment of the text in the "A1" cell
            Style style = cell.GetStyle();

            // Setting the text direction from right to left
            style.TextDirection = TextDirectionType.RightToLeft;

            cell.SetStyle(style);

            // Saving the Excel file
            workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003);
            // ExEnd:1
        }
开发者ID:aspose-cells,项目名称:Aspose.Cells-for-.NET,代码行数:35,代码来源:TextDirection.cs

示例15: ConvertToFile

        /// <summary>
        /// Converts binary to blob pointer
        /// </summary>
        /// <param name="category">The file category.</param>
        /// <param name="data">The data.</param>
        /// <param name="name">The name.</param>
        /// <returns>Blob Pointer</returns>
        public static string ConvertToFile(string category, string name, byte[] data)
        {
            if (data == null)
            {
                return null;
            }

            using (Stream stream = new MemoryStream(data))
            {
                // convert doc, xls -> docx, xlsx
                Stream streamToSave = new MemoryStream();
                if (FileTypeDetector.IsDoc(data))
                {
                    Document doc = new Document(stream);
                    doc.RemoveMacros();
                    doc.Save(streamToSave, Aspose.Words.SaveFormat.Docx);
                }
                else if (FileTypeDetector.IsXls(data))
                {
                    Workbook xls = new Workbook(stream);
                    xls.RemoveMacro();
                    xls.Save(streamToSave, Aspose.Cells.SaveFormat.Xlsx);
                }
                else
                {
                    streamToSave = stream;
                }

                // save to file
                streamToSave.Position = 0;
                string result = BlobStoreProvider.Instance.PutBlob(category, name, streamToSave);

                return result;
            }
        }
开发者ID:khangtran-steadfast,项目名称:DatabaseConversion,代码行数:42,代码来源:BlobConverter.cs


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