本文整理汇总了C#中Workbook.LoadFromStream方法的典型用法代码示例。如果您正苦于以下问题:C# Workbook.LoadFromStream方法的具体用法?C# Workbook.LoadFromStream怎么用?C# Workbook.LoadFromStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Workbook
的用法示例。
在下文中一共展示了Workbook.LoadFromStream方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnRead_Click
private void btnRead_Click(object sender, EventArgs e)
{
using (Stream buffer = this.WriteFormulas())
{
//load
Workbook workbook = new Workbook();
workbook.LoadFromStream(buffer);
//calculate all cells' formula
workbook.CalculateAllValue();
//read cells' value to data table
Worksheet sheet = workbook.Worksheets[0];
DataTable dataTable = new DataTable();
dataTable.Columns.Add("Formulas", typeof(String));
dataTable.Columns.Add("Results", typeof(Object));
foreach (CellRange row in sheet["A5:B46"].Rows)
{
String formula = row.Columns[1].Formula;
Object value = row.Columns[1].FormulaValue;
dataTable.Rows.Add(formula, value);
}
this.dataGrid1.DataSource = dataTable;
}
}
示例2: LayoutRoot_Loaded
private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
{
Assembly assembly = this.GetType().Assembly;
foreach (String name in assembly.GetManifestResourceNames())
{
if (name.EndsWith(".DatatableSample.xls"))
{
using (Stream stream = assembly.GetManifestResourceStream(name))
{
Workbook workbook = new Workbook();
workbook.LoadFromStream(stream);
Worksheet sheet = workbook.Worksheets[0];
this.dataSource = new List<Country>();
foreach (CellRange row in sheet.Rows)
{
if (row != null && row.Cells != null && row.Cells.Length == 5
&& !row.Cells[0].IsBlank)
{
if (row.Cells[0].Row == 1)
{
continue;
}
this.dataSource.Add(new Country()
{
Name = row.Cells[0].Value,
Capital = row.Cells[1].Value,
Continent = row.Cells[2].Value,
Area = row.Cells[3].NumberValue,
Population = Convert.ToInt64(row.Cells[4].NumberValue)
});
}
else
{
break;
}
}
this.dataGrid.ItemsSource = this.dataSource;
}
this.buttonGenerate.IsEnabled = true;
}
else if(name.EndsWith(".MarkerDesignerSample.xls"))
{
using (Stream stream = assembly.GetManifestResourceStream(name))
{
this.template = new Workbook();
this.template.LoadFromStream(stream);
}
}
}
}
示例3: 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);
}
示例4: 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"));
//.........这里部分代码省略.........
示例5: btnCalculate_Click
private void btnCalculate_Click(object sender, EventArgs e)
{
using (Stream buffer = this.WriteFormulas())
{
//load
Workbook workbook = new Workbook();
workbook.LoadFromStream(buffer);
//calculate formula
Object b3 = workbook.CaculateFormulaValue("Sheet1!$B$3");
Object c3 = workbook.CaculateFormulaValue("Sheet1!$C$3");
String formula = "Sheet1!$B$3 + Sheet1!$C$3";
Object value = workbook.CaculateFormulaValue(formula);
String message
= String.Format("Sheet1!$B$3 = {0}, Sheet1!$C$3 = {1}, {2} = {3}",
b3, c3, formula, value);
MessageBox.Show(message);
}
}
示例6: btnExport_Click
private void btnExport_Click(object sender, System.EventArgs e)
{
using (Stream buffer = this.WriteFormulas())
{
//load
Workbook workbook = new Workbook();
workbook.LoadFromStream(buffer);
//calculate all cells
workbook.CalculateAllValue();
//export
Worksheet sheet = workbook.Worksheets[0];
this.dataGrid1.DataSource = sheet.ExportDataTable(sheet["A4:B46"], true, true);
}
}