本文整理汇总了C#中Workbook.SaveToFile方法的典型用法代码示例。如果您正苦于以下问题:C# Workbook.SaveToFile方法的具体用法?C# Workbook.SaveToFile怎么用?C# Workbook.SaveToFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Workbook
的用法示例。
在下文中一共展示了Workbook.SaveToFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnRun_Click
private void btnRun_Click(object sender, RoutedEventArgs e)
{
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
sheet.Range["B1"].Text = "Font setting";
sheet.Range["B1"].Style.Font.IsBold = true;
sheet.Range["B3"].Text = "Arial";
sheet.Range["B3"].Style.Font.FontName = "Arial";
sheet.Range["B4"].Text = "Large size";
sheet.Range["B4"].Style.Font.Size = 20;
sheet.Range["B5"].Text = "Bold";
sheet.Range["B5"].Style.Font.IsBold = true;
sheet.Range["B6"].Text = "Italic";
sheet.Range["B6"].Style.Font.IsItalic = true;
sheet.Range["B7"].Text = "Superscript";
sheet.Range["B7"].Style.Font.IsSuperscript = true;
sheet.Range["B8"].Text = "Colored";
sheet.Range["B8"].Style.Font.Color = System.Drawing.Color.FromArgb(255, 125, 125);
sheet.Range["B9"].Text = "Underline";
sheet.Range["B9"].Style.Font.Underline = FontUnderlineType.Single;
sheet.AutoFitColumn(2);
workbook.SaveToFile("Sample.xls");
ExcelDocViewer(workbook.FileName);
}
示例2: SaveData
/// <summary>
/// zapisywanie danych do excelu
/// </summary>
/// <param name="DataCollection">kolekcja danych gps </param>
/// <param name="filePath">scierzka pliku</param>
public void SaveData(ObservableCollection<DataGps> DataCollection, string filePath)
{
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
int row = 2;
var obj = DataCollection.FirstOrDefault();
if (obj == null) return;
sheet.Range["A" + 1].Text = nameof(obj.GeoHeight);
sheet.Range["B" + 1].Text = nameof(obj.GeoWidth);
sheet.Range["C" + 1].Text = nameof(obj.BoatDirection);
sheet.Range["D" + 1].Text = nameof(obj.BoatSpeed);
sheet.Range["E" + 1].Text = nameof(obj.WindDirection);
sheet.Range["F" + 1].Text = nameof(obj.WindSpeed);
sheet.Range["G" + 1].Text = nameof(obj.SecondsFromStart);
foreach (var item in DataCollection)
{
sheet.Range["A" + row].Text = item.GeoHeight;
sheet.Range["B" + row].Text = item.GeoWidth;
sheet.Range["C" + row].Text = item.BoatDirection.ToString(CultureInfo.InvariantCulture);
sheet.Range["D" + row].Text = item.BoatSpeed.ToString(CultureInfo.InvariantCulture);
sheet.Range["E" + row].Text = item.WindDirection.ToString(CultureInfo.InvariantCulture);
sheet.Range["F" + row].Text = item.WindDirection.ToString(CultureInfo.InvariantCulture);
sheet.Range["G" + row].Text = item.SecondsFromStart.ToString(CultureInfo.InvariantCulture);
row++;
}
workbook.SaveToFile(filePath);
System.Diagnostics.Process.Start(workbook.FileName);
}
示例3: btnRead_Click
private void btnRead_Click(object sender, RoutedEventArgs e)
{
Workbook workbook = new Workbook();
//Initailize worksheet
workbook.CreateEmptySheets(1);
Worksheet sheet = workbook.Worksheets[0];
sheet.Name = "Chart data";
sheet.GridLinesVisible = false;
//Writes chart data
CreateChartData(sheet);
//Add a new chart worsheet to workbook
Chart chart = sheet.Charts.Add();
//Set region of chart data
chart.DataRange = sheet.Range["A1:C5"];
chart.SeriesDataFromRange = false;
//Set position of chart
chart.LeftColumn = 1;
chart.TopRow = 7;
chart.RightColumn = 11;
chart.BottomRow = 30;
if (chk3D.IsChecked==true)
{
chart.ChartType = ExcelChartType.Area3D;
}
else
{
chart.ChartType = ExcelChartType.Area;
}
//Chart title area
chart.ChartTitle = "Sales market by country";
chart.ChartTitleArea.IsBold = true;
chart.ChartTitleArea.Size = 12;
chart.PrimaryCategoryAxis.Title = "Country";
chart.PrimaryCategoryAxis.Font.IsBold = true;
chart.PrimaryCategoryAxis.TitleArea.IsBold = true;
chart.PrimaryValueAxis.Title = "Sales(in Dollars)";
chart.PrimaryValueAxis.HasMajorGridLines = true;
chart.PrimaryValueAxis.TitleArea.TextRotationAngle = 90;
chart.PrimaryValueAxis.MinValue = 1000;
chart.PrimaryValueAxis.TitleArea.IsBold = true;
foreach (Spire.Xls.Charts.ChartSerie cs in chart.Series)
{
cs.Format.Options.IsVaryColor = true;
cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
}
chart.Legend.Position = LegendPositionType.Top;
workbook.SaveToFile("Sample.xls");
ExcelDocViewer(workbook.FileName);
}
示例4: SaveAndExport
public void SaveAndExport(bool excel, bool pdf)
{
pack.Save();
pack.Dispose();
if (pdf)
{
Workbook pdfWork = new Workbook();
pdfWork.LoadFromFile(@"Report.xlsx");
pdfWork.SaveToFile(fileinfo.FullName.Replace(".xlsx", ".pdf"), Spire.Xls.FileFormat.PDF);
}
}
示例5: ConvertXLFiles
public static int ConvertXLFiles(string outDir, int start)
{
DirectoryInfo downloadedMessageInfo = new DirectoryInfo(outDir);
Workbook workbook = new Workbook();
foreach (FileInfo file in downloadedMessageInfo.GetFiles("*.xlsx"))
{
Console.WriteLine("Loading : " + file.Name);
workbook.LoadFromFile(file.FullName, ExcelVersion.Version2013);
workbook.SaveToFile(string.Format("{0}{1:000}.pdf", outDir, start), FileFormat.PDF);
file.Delete();
start++;
}
foreach (FileInfo file in downloadedMessageInfo.GetFiles("*.xls"))
{
Console.WriteLine("Loading ->" + file.Name);
workbook.LoadFromFile(file.FullName, ExcelVersion.Version97to2003);
workbook.SaveToFile(string.Format("{0}{1:000}.pdf", outDir, start), FileFormat.PDF);
Console.WriteLine("Saving ->" + string.Format("{0}{1:000}.pdf", outDir, start));
file.Delete();
start++;
}
return start;
}
示例6: Main
static void Main(string[] args)
{
var existingFile = new FileInfo("FMCG2.xlsx");
// Open and read the XlSX file.
using (var package = new ExcelPackage(existingFile))
{
// Get the work book in the file
ExcelWorkbook workBook = package.Workbook;
if (workBook != null)
{
if (workBook.Worksheets.Count > 0)
{
var newfile = new FileInfo("new.xlsx");
ExcelPackage pck = new ExcelPackage(newfile);
var ws = pck.Workbook.Worksheets.Add("data", workBook.Worksheets["Reports"]);
pck.Save();
//var drawings = workBook.Worksheets["Reports"].Drawings;
//workBook.Worksheets["Calculation"].Cells["D4"].Value = 119;
//workBook.Worksheets["Calculation"].Cells["D5"].Value = 519;
//IEnumerable<int> arr = new List<int>() { 1, 2, 3, 4, 5 };
//Int32[] arr2 = new Int32[] { 1, 2, 3, 4, 5 };
//ExcelAddress address = new ExcelAddress("D1:D5");
//workBook.Worksheets["Calculation"].Select(address);
//workBook.Worksheets["Calculation"].SelectedRange.LoadFromCollection<int>(arr);
//workBook.Worksheets["Calculation"].Calculate();
//MemoryStream memStream1 = new MemoryStream(); // = new MemoryStream(pck.GetAsByteArray());
//package.SaveAs(memStream1);
//memStream1.Position = 0;
//Workbook spireworkbook2 = new Workbook();
//MemoryStream memStream2 = new MemoryStream();
//spireworkbook.SaveToStream(memStream2);
//spireworkbook.LoadFromStream(memStream1);
Workbook spireworkbook = new Workbook();
spireworkbook.LoadFromFile("new.xlsx", ExcelVersion.Version2007);
spireworkbook.SaveToFile("results.pdf", Spire.Xls.FileFormat.PDF);
Console.Read();
}
}
}
}
示例7: btnRun_Click
private void btnRun_Click(object sender, System.EventArgs e)
{
Workbook workbook = new Workbook();
//Initailize worksheet
Worksheet sheet = workbook.Worksheets[0];
sheet.InsertDataTable((DataTable)this.dataGrid1.DataSource,true,2,1,-1,-1);
//Sets body style
CellStyle oddStyle = workbook.Styles.Add("oddStyle");
oddStyle.Borders[BordersLineType.EdgeLeft].LineStyle = LineStyleType.Thin;
oddStyle.Borders[BordersLineType.EdgeRight].LineStyle = LineStyleType.Thin;
oddStyle.Borders[BordersLineType.EdgeTop].LineStyle = LineStyleType.Thin;
oddStyle.Borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Thin;
oddStyle.KnownColor = ExcelColors.LightGreen1;
CellStyle evenStyle = workbook.Styles.Add("evenStyle");
evenStyle.Borders[BordersLineType.EdgeLeft].LineStyle = LineStyleType.Thin;
evenStyle.Borders[BordersLineType.EdgeRight].LineStyle = LineStyleType.Thin;
evenStyle.Borders[BordersLineType.EdgeTop].LineStyle = LineStyleType.Thin;
evenStyle.Borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Thin;
evenStyle.KnownColor = ExcelColors.LightTurquoise;
foreach (CellRange range in sheet.AllocatedRange.Rows)
{
if (range.Row % 2 == 0)
range.CellStyleName = evenStyle.Name;
else
range.CellStyleName = oddStyle.Name;
}
//Sets header style
CellStyle styleHeader = sheet.Rows[0].Style;
styleHeader.Borders[BordersLineType.EdgeLeft].LineStyle = LineStyleType.Thin;
styleHeader.Borders[BordersLineType.EdgeRight].LineStyle = LineStyleType.Thin;
styleHeader.Borders[BordersLineType.EdgeTop].LineStyle = LineStyleType.Thin;
styleHeader.Borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Thin;
styleHeader.VerticalAlignment = VerticalAlignType.Center;
styleHeader.KnownColor = ExcelColors.Green;
styleHeader.Font.KnownColor = ExcelColors.White;
styleHeader.Font.IsBold = true;
sheet.Columns[sheet.AllocatedRange.LastColumn - 1].Style.NumberFormat = "\"$\"#,##0";
sheet.Columns[sheet.AllocatedRange.LastColumn - 2].Style.NumberFormat = "\"$\"#,##0";
sheet.AllocatedRange.AutoFitColumns();
sheet.AllocatedRange.AutoFitRows();
sheet.Rows[0].RowHeight = 20;
workbook.SaveToFile("sample.xls");
ExcelDocViewer( workbook.FileName );
}
示例8: btnRun_Click
private void btnRun_Click(object sender, System.EventArgs e)
{
Workbook workbook = new Workbook();
//Initailize worksheet
workbook.CreateEmptySheets(1);
Worksheet sheet = workbook.Worksheets[0];
sheet.GridLinesVisible = false;
//Writes filter data
CreateFilterData(sheet);
sheet.AutoFilters.Range = sheet.Range["A1:C1"];
workbook.SaveToFile("Sample.xls");
ExcelDocViewer(workbook.FileName);
}
示例9: btnRun_Click
private void btnRun_Click(object sender, System.EventArgs e)
{
Workbook workbook = new Workbook();
//Initailize worksheet
workbook.CreateEmptySheets(1);
Worksheet sheet = workbook.Worksheets[0];
//Protect workshet
sheet.Protect( this.textBox1.Text );
//Protect cells
sheet.Range["A1"].Text = "Locked";
sheet.Range["B1"].Text = "Unlocked";
sheet.Range["A1"].Style.Locked = true;
sheet.Range["B1"].Style.Locked = false;
//Protect workbook
workbook.Protect(this.textBox1.Text);
workbook.SaveToFile("Sample.xls");
ExcelDocViewer(workbook.FileName);
}
示例10: btnRun_Click
private void btnRun_Click(object sender, System.EventArgs e)
{
Workbook workbook = new Workbook();
//Initailize worksheet
workbook.CreateEmptySheets(1);
Worksheet sheet = workbook.Worksheets[0];
sheet.Name = "Chart data";
sheet.GridLinesVisible = false;
//Add a new chart worsheet to workbook
Chart chart = sheet.Charts.Add();
CreateChartData(sheet);
CreateChart(sheet, chart);
chart.ChartType = ExcelChartType.ScatterMarkers;
chart.Legend.Position = LegendPositionType.Top;
workbook.SaveToFile("Sample.xls");
ExcelDocViewer(workbook.FileName);
}
示例11: btnRun_Click
private void btnRun_Click(object sender, System.EventArgs e)
{
Workbook workbook = new Workbook();
//Initailize worksheet
workbook.CreateEmptySheets(1);
Worksheet sheet = workbook.Worksheets[0];
sheet.Name = "Chart data";
sheet.GridLinesVisible = false;
//Writes chart data
CreateChartData(sheet);
//Add a new chart worsheet to workbook
Chart chart = sheet.Charts.Add();
//Set region of chart data
chart.DataRange = sheet.Range["A1:C5"];
chart.SeriesDataFromRange = false;
//Set position of chart
chart.LeftColumn = 1;
chart.TopRow = 6;
chart.RightColumn = 11;
chart.BottomRow = 29;
chart.ChartType = ExcelChartType.Doughnut;
//Chart title
chart.ChartTitle = "Sales market by country";
chart.ChartTitleArea.IsBold = true;
chart.ChartTitleArea.Size = 12;
foreach (Charts.ChartSerie cs in chart.Series)
{
cs.Format.Options.IsVaryColor = true;
cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
}
chart.PlotArea.Fill.Visible = false;
chart.Legend.Position = LegendPositionType.Top;
workbook.SaveToFile("Sample.xls");
ExcelDocViewer(workbook.FileName);
}
示例12: btnRun_Click
private void btnRun_Click(object sender, System.EventArgs e)
{
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"..\..\..\..\..\..\Data\MarkerDesignerSample.xls");
DataTable dt = (DataTable)dataGrid1.DataSource;
Worksheet sheet = workbook.Worksheets[0];
workbook.MarkerDesigner.AddParameter("Variable1",1234.5678);
workbook.MarkerDesigner.AddDataTable("Country",dt);
workbook.MarkerDesigner.Apply();
sheet.AllocatedRange.AutoFitRows();
sheet.AllocatedRange.AutoFitColumns();;
workbook.SaveToFile("Sample.xls");
ExcelDocViewer(workbook.FileName);
}
示例13: btnRun_Click
private void btnRun_Click(object sender, System.EventArgs e)
{
Workbook workbook = new Workbook();
//Opening excel from a stream
FileStream fileStream = File.OpenRead(@"..\..\..\..\..\..\Data\ReadStreamSample.xls");
fileStream.Seek(0, SeekOrigin.Begin);
workbook.LoadFromStream(fileStream);
workbook.SaveToFile("Sample.xls");
ExcelDocViewer(workbook.FileName);
}
示例14: btnRun_Click
private void btnRun_Click(object sender, System.EventArgs e)
{
Workbook workbook = new Workbook();
//Initailize worksheet
workbook.CreateEmptySheets(1);
Worksheet sheet = workbook.Worksheets[0];
sheet.Name = "Chart data";
sheet.GridLinesVisible = false;
//Writes chart data
CreateChartData(sheet);
//Add a new chart worsheet to workbook
Chart chart = sheet.Charts.Add();
if (checkBox1.Checked)
{
chart.ChartType = ExcelChartType.LineMarkers100PercentStacked;
}
else
{
chart.ChartType = ExcelChartType.Line100PercentStacked;
}
//Set region of chart data
chart.DataRange = sheet.Range["A1:E5"];
//Set position of chart
chart.LeftColumn = 1;
chart.TopRow = 6;
chart.RightColumn = 11;
chart.BottomRow = 29;
//Chart title
chart.ChartTitle = "Sales market by country";
chart.ChartTitleArea.IsBold = true;
chart.ChartTitleArea.Size = 12;
chart.PrimaryCategoryAxis.Title = "Month";
chart.PrimaryCategoryAxis.Font.IsBold = true;
chart.PrimaryCategoryAxis.TitleArea.IsBold = true;
chart.PrimaryValueAxis.Title = "Sales(%)";
chart.PrimaryValueAxis.HasMajorGridLines = false;
chart.PrimaryValueAxis.TitleArea.TextRotationAngle = 90;
chart.PrimaryValueAxis.TitleArea.IsBold = true;
foreach (Charts.ChartSerie cs in chart.Series)
{
cs.Format.Options.IsVaryColor = true;
cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
}
chart.Legend.Position = LegendPositionType.Top;
workbook.SaveToFile("Sample.xls");
ExcelDocViewer(workbook.FileName);
}
示例15: btnRun_Click
private void btnRun_Click(object sender, System.EventArgs e)
{
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
sheet.Range["B1"].Text = "Text Align";
sheet.Range["B1"].Style.Font.IsBold = true;
sheet.Range["B3"].Text = "Top";
sheet.Range["B3"].Style.VerticalAlignment = VerticalAlignType.Top;
sheet.Range["B4"].Text = "Center";
sheet.Range["B4"].Style.VerticalAlignment = VerticalAlignType.Center;
sheet.Range["B5"].Text = "Bottom";
sheet.Range["B5"].Style.VerticalAlignment = VerticalAlignType.Bottom;
sheet.Range["B6"].Text = "General";
sheet.Range["B6"].Style.HorizontalAlignment = HorizontalAlignType.General;
sheet.Range["B7"].Text = "Left";
sheet.Range["B7"].Style.HorizontalAlignment = HorizontalAlignType.Left;
sheet.Range["B8"].Text = "Center";
sheet.Range["B8"].Style.HorizontalAlignment = HorizontalAlignType.Center;
sheet.Range["B9"].Text = "Right";
sheet.Range["B9"].Style.HorizontalAlignment = HorizontalAlignType.Right;
sheet.Range["B10"].Text = "Rotation 90 degree";
sheet.Range["B10"].Style.Rotation = 90;
sheet.Range["B11"].Text = "Rotation 45 degree";
sheet.Range["B11"].Style.Rotation = 45;
sheet.AllocatedRange.AutoFitColumns();
sheet.Range["B3:B5"].RowHeight = 20;
workbook.SaveToFile("Sample.xls");
ExcelDocViewer(workbook.FileName);
}