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


C# XLWorkbook.SaveAs方法代码示例

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


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

示例1: Create

        public void Create(string filePath)
        {
            string tempFile = ExampleHelper.GetTempFilePath(filePath);
            try
            {
                new BasicTable().Create(tempFile);
                var workbook = new XLWorkbook(tempFile);
                var ws = workbook.Worksheet(1);

                // Get a range object
                var rngHeaders = ws.Range("B3:F3");

                // Insert some rows/columns before the range
                ws.Row(1).InsertRowsAbove(2);
                ws.Column(1).InsertColumnsBefore(2);

                // Change the background color of the headers
                rngHeaders.Style.Fill.BackgroundColor = XLColor.LightSalmon;

                ws.Columns().AdjustToContents();

                workbook.SaveAs(filePath);
            }
            finally
            {
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            }
        }
开发者ID:hal1932,项目名称:ClosedXML,代码行数:31,代码来源:ShiftingRanges.cs

示例2: Create

        // Public
        public void Create(String filePath)
        {
            var workbook = new XLWorkbook();
            var ws = workbook.Worksheets.Add("Clearing Ranges");
            foreach (var ro in Enumerable.Range(1, 10))
            {
                foreach (var co in Enumerable.Range(1, 10))
                {
                    var cell = ws.Cell(ro, co);
                    cell.Value = cell.Address.ToString();
                    cell.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
                    cell.Style.Fill.BackgroundColor = XLColor.Turquoise;
                    cell.Style.Font.Bold = true;
                }
            }

            // Clearing a range
            ws.Range("B1:C2").Clear();

            // Clearing a row in a range
            ws.Range("B4:C5").Row(1).Clear();

            // Clearing a column in a range
            ws.Range("E1:F4").Column(2).Clear();

            // Clear an entire row
            ws.Row(7).Clear();

            // Clear an entire column
            ws.Column("H").Clear();

            workbook.SaveAs(filePath);
        }
开发者ID:hal1932,项目名称:ClosedXML,代码行数:34,代码来源:ClearingRanges.cs

示例3: ExportToExcelFile

        private static void ExportToExcelFile(DataGridView dGV, string filename, string tabName)
        {
            //Creating DataTable
            DataTable dt = new DataTable();

            //Adding the Columns
            foreach (DataGridViewColumn column in dGV.Columns)
            {
                dt.Columns.Add(column.HeaderText, column.ValueType);
            }

            //Adding the Rows
            foreach (DataGridViewRow row in dGV.Rows)
            {
                dt.Rows.Add();
                foreach (DataGridViewCell cell in row.Cells)
                {
                    dt.Rows[dt.Rows.Count - 1][cell.ColumnIndex] = cell.Value.ToString();
                }
            }

            using (XLWorkbook wb = new XLWorkbook())
            {
                wb.Worksheets.Add(dt, tabName);
                wb.SaveAs(filename);
            }
        }  
开发者ID:EnriqueRivera,项目名称:InventoryApplication,代码行数:27,代码来源:Utils.cs

示例4: Create

        // Public
        public void Create(String filePath)
        {
            var workbook = new XLWorkbook();
            var ws = workbook.Worksheets.Add("Inserting Columns");

            // Color the entire spreadsheet using columns
            ws.Columns().Style.Fill.BackgroundColor = XLColor.LightCyan;

            // Put a value in a few cells
            foreach (var r in Enumerable.Range(1, 5))
                foreach (var c in Enumerable.Range(1, 5))
                    ws.Cell(r, c).Value = "X";

            var blueColumn = ws.Column(2);
            var redColumn = ws.Column(5);

            blueColumn.Style.Fill.BackgroundColor = XLColor.Blue;
            blueColumn.InsertColumnsAfter(2);

            redColumn.Style.Fill.BackgroundColor = XLColor.Red;
            redColumn.InsertColumnsBefore(2);

            ws.Rows(3, 4).Style.Fill.BackgroundColor = XLColor.Orange;
            ws.Range("B1:D1").InsertColumnsAfter(2);
            ws.Range("B2:D2").InsertColumnsBefore(2);
            ws.Range("B3:D3").InsertColumnsAfter(2);
            ws.Range("B4:D4").InsertColumnsBefore(2);

            workbook.SaveAs(filePath);
        }
开发者ID:hal1932,项目名称:ClosedXML,代码行数:31,代码来源:InsertColumns.cs

示例5: Create

        public void Create(string filePath)
        {
            string tempFile = ExampleHelper.GetTempFilePath(filePath);
            try
            {
                new BasicTable().Create(tempFile);
                var workbook = new XLWorkbook(tempFile);

                var ws = workbook.Worksheet(1);

                var rngTable = ws.Range("B2:F6");

                rngTable.Transpose(XLTransposeOptions.MoveCells);

                ws.Columns().AdjustToContents();

                workbook.SaveAs(filePath);
            }
            finally
            {
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            }
        }
开发者ID:hal1932,项目名称:ClosedXML,代码行数:26,代码来源:TransposeRanges.cs

示例6: Export

        public void Export(string filePath)
        {
            using (var workbook = new XLWorkbook(XLEventTracking.Disabled))
            {

                IEnumerable<CultureInfo> cultures = null;
                if (Cultures != null)
                    cultures = Cultures.Select(vc => vc.Culture);
                else
                    cultures = Solution.Cultures.Keys;

                IEnumerable<VSProject> projects = Projects;
                if (Projects == null)
                    projects = (IEnumerable<VSProject>)Solution.Projects.Values;

                foreach (var project in projects)
                {
                    var data = GetData(project, cultures);

                    if (IncludeProjectsWithoutTranslations || data.Count() > 0)
                        AddProject(project, workbook, cultures, data);
                }

                workbook.SaveAs(filePath);
            }
        }
开发者ID:dnstech,项目名称:ResxManager,代码行数:26,代码来源:XlsxConverter.cs

示例7: CreateExcelFile

        private static void CreateExcelFile(ChromeDriver driver)
        {
            var homeTeams = driver.FindElements(By.ClassName("team-home"));
            var awayTeams = driver.FindElements(By.ClassName("team-away"));
            var scores = driver.FindElements(By.ClassName("score"));

            var wb = new XLWorkbook();
            var ws = wb.Worksheets.Add("Scores");

            ws.Cell("A1").Value = "Home Team";
            ws.Cell("B1").Value = "Score";
            ws.Cell("C1").Value = "Away Team";

            for (int i = 0; i < homeTeams.Count; i++)
            {
                string homeTeam = homeTeams[i].Text;
                string score = scores[i].Text;
                string awayTeam = awayTeams[i].Text;

                ws.Cell("A" + (i + 2)).Value = homeTeam;
                ws.Cell("B" + (i + 2)).Value = score;
                ws.Cell("C" + (i + 2)).Value = awayTeam;
            }

            // Beautify
            ws.Range("A1:C1").Style.Font.Bold = true;
            ws.Columns().AdjustToContents();

            wb.SaveAs("../../../../FlashScore.xlsx");
        }
开发者ID:stoberov,项目名称:Betman,代码行数:30,代码来源:FlashScores.cs

示例8: CreateExcelFile

        private static void CreateExcelFile(ChromeDriver driver)
        {
            var upcomingEvents = driver.FindElementsByCssSelector(".event.active");

            var wb = new XLWorkbook();
            var ws = wb.Worksheets.Add("Games");

            ws.Cell("A1").Value = "Games";
            ws.Cell("B1").Value = "Home";
            ws.Cell("C1").Value = "Draw";
            ws.Cell("D1").Value = "Away";

            for (int i = 0; i < upcomingEvents.Count; i++)
            {
                string eventName = upcomingEvents[i].FindElement(By.ClassName("eventName")).Text;
                string homeOdd = upcomingEvents[i].FindElement(By.ClassName("home")).Text;
                string drawOdd = upcomingEvents[i].FindElement(By.ClassName("draw")).Text;
                string awayOdd = upcomingEvents[i].FindElement(By.ClassName("away")).Text;

                ws.Cell("A" + (i + 2)).Value = eventName;
                ws.Cell("B" + (i + 2)).Value = homeOdd;
                ws.Cell("C" + (i + 2)).Value = drawOdd;
                ws.Cell("D" + (i + 2)).Value = awayOdd;
            }

            // Beautify
            ws.Range("A1:D1").Style.Font.Bold = true;
            ws.Columns().AdjustToContents();

            wb.SaveAs("../../../../Events.xlsx");
        }
开发者ID:stoberov,项目名称:Betman,代码行数:31,代码来源:Sportingbet.cs

示例9: Create

        // Public
        public void Create(String filePath)
        {
            var workbook = new XLWorkbook();
            var ws = workbook.Worksheets.Add("Merge Cells");

            // Merge a row
            ws.Cell("B2").Value = "Merged Row(1) of Range (B2:D3)";
            ws.Range("B2:D3").Row(1).Merge();

            // Merge a column
            ws.Cell("F2").Value = "Merged Column(1) of Range (F2:G8)";
            ws.Cell("F2").Style.Alignment.WrapText = true;
            ws.Range("F2:G8").Column(1).Merge();

            // Merge a range
            ws.Cell("B4").Value = "Merged Range (B4:D6)";
            ws.Cell("B4").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
            ws.Cell("B4").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
            ws.Range("B4:D6").Merge();

            // Unmerging a range...
            ws.Cell("B8").Value = "Unmerged";
            ws.Range("B8:D8").Merge();
            ws.Range("B8:D8").Unmerge();

            workbook.SaveAs(filePath);
        }
开发者ID:hal1932,项目名称:ClosedXML,代码行数:28,代码来源:MergeCells.cs

示例10: Create

        // Public
        public void Create(String filePath)
        {
            var workbook = new XLWorkbook();
            var ws = workbook.Worksheets.Add("Inserting Rows");

            // Color the entire spreadsheet using rows
            ws.Rows().Style.Fill.BackgroundColor = XLColor.LightCyan;

            // Put a value in a few cells
            foreach (var r in Enumerable.Range(1, 5))
                foreach (var c in Enumerable.Range(1, 5))
                    ws.Cell(r, c).Value = "X";

            var blueRow = ws.Row(2);
            var redRow = ws.Row(5);

            blueRow.Style.Fill.BackgroundColor = XLColor.Blue;
            blueRow.InsertRowsBelow(2);

            redRow.Style.Fill.BackgroundColor = XLColor.Red;
            redRow.InsertRowsAbove(2);

            ws.Columns(3, 4).Style.Fill.BackgroundColor = XLColor.Orange;
            ws.Range("A2:A4").InsertRowsBelow(2);
            ws.Range("B2:B4").InsertRowsAbove(2);
            ws.Range("C2:C4").InsertRowsBelow(2);
            ws.Range("D2:D4").InsertRowsAbove(2);

            workbook.SaveAs(filePath);
        }
开发者ID:hal1932,项目名称:ClosedXML,代码行数:31,代码来源:InsertRows.cs

示例11: DataTableExport

        public void DataTableExport(DataTable dataTable, string filePath, string title)
        {
            if (string.IsNullOrWhiteSpace(filePath))
                throw new FileNotFoundException("Incorrect file path.");

            if ((dataTable == null) || (dataTable.Rows.Count == 0))
                throw new ArgumentException("Empty data table.");

            var workbook = new XLWorkbook();
            var worksheet = workbook.Worksheets.Add(title);

            if (IncludeTitle)
            {
                worksheet.Cell(1, 1).Value = title;
                worksheet.Range(1, 1, 1, dataTable.Columns.Count).Merge().AddToNamed("Titles");

                var titlesStyle = workbook.Style;
                titlesStyle.Font.Bold = true;
                titlesStyle.Font.FontSize = 16;
                titlesStyle.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
                titlesStyle.Fill.BackgroundColor = XLColor.Cyan;
                workbook.NamedRanges.NamedRange("Titles").Ranges.Style = titlesStyle;
            }
            worksheet.Cell(2, 1).InsertTable(dataTable.AsEnumerable());

            worksheet.Columns().AdjustToContents();

            workbook.SaveAs(filePath);
        }
开发者ID:CyberNyanta,项目名称:QueryBuilder,代码行数:29,代码来源:DataTableToExcelExporter.cs

示例12: WriteBeaches

        public static void WriteBeaches()
        {
            var workbook = new XLWorkbook();
            var worksheet = workbook.Worksheets.Add("Плажове");

            for(int i = 0; i < Beach.beaches.Count; i++)
            {
                Beach current = Beach.beaches[i];
                int rowIdx = i + 2;
                worksheet.Cell(f("A", rowIdx)).Value = current.name;
                worksheet.Cell(f("B", rowIdx)).Value = current.location;
                worksheet.Cell(f("C", rowIdx)).Value = current.nCar;
                worksheet.Cell(f("D", rowIdx)).Value = current.nCity;
                worksheet.Cell(f("E", rowIdx)).Value = current.nFoot;

                worksheet.Cell(f("F", rowIdx)).Value = current.facilties[0];
                worksheet.Cell(f("G", rowIdx)).Value = current.facilties[1];
                worksheet.Cell(f("H", rowIdx)).Value = current.facilties[2];
                worksheet.Cell(f("I", rowIdx)).Value = current.facilties[3];

                worksheet.Cell(f("J", rowIdx)).Value = current.Density;
                worksheet.Cell(f("K", rowIdx)).Value = current.Polution;
                worksheet.Cell(f("L", rowIdx)).Value = current.Grade;
                worksheet.Cell(f("M", rowIdx)).Value = current.People;
            }

            workbook.SaveAs("ало.xlsx");
        }
开发者ID:3c3,项目名称:StatProcessor,代码行数:28,代码来源:ExcelWriter.cs

示例13: Create

 public void Create(String filePath)
 {
     var workbook = new XLWorkbook();
     var worksheet = workbook.Worksheets.Add("Sample Sheet");
     worksheet.Cell("A1").Value = "Hello World!";
     workbook.SaveAs(filePath);
 }
开发者ID:hal1932,项目名称:ClosedXML,代码行数:7,代码来源:HelloWorld.cs

示例14: Create

        public void Create(string filePath)
        {
            string tempFile = ExampleHelper.GetTempFilePath(filePath);
            try
            {
                //Note: Prepare
                {
                    var workbook = new XLWorkbook();
                    workbook.Worksheets.Add("1");
                    workbook.Worksheets.Add("2");
                    workbook.Worksheets.Add("3");
                    workbook.Worksheets.Add("4");
                    workbook.SaveAs(tempFile);
                }

                //Note: Delate few worksheet
                {
                    var workbook = new XLWorkbook(tempFile);
                    workbook.Worksheets.Delete("1");
                    workbook.Worksheets.Delete("2");
                    workbook.SaveAs(filePath);
                }
            }
            finally
            {
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            }
        }
开发者ID:hal1932,项目名称:ClosedXML,代码行数:31,代码来源:DeleteFewWorksheets.cs

示例15: Create

        public void Create(string filePath)
        {
            var tempFile = ExampleHelper.GetTempFilePath(filePath);
            try
            {
                new BasicTable().Create(tempFile);
                var workbook = new XLWorkbook(tempFile);
                var ws = workbook.Worksheet(1);

                // Define a range with the data
                var firstTableCell = ws.FirstCellUsed();
                var lastTableCell = ws.LastCellUsed();
                var rngData = ws.Range(firstTableCell.Address, lastTableCell.Address);

                // Copy the table to another worksheet
                var wsCopy = workbook.Worksheets.Add("Contacts Copy");
                wsCopy.Cell(1, 1).Value = rngData;

                workbook.SaveAs(filePath);
            }
            finally
            {
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            }
        }
开发者ID:hal1932,项目名称:ClosedXML,代码行数:28,代码来源:CopyingRanges.cs


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