|
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
//Set the default application version as Excel 2013.
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook;
IWorksheet worksheet;
if (count == 1)
{
//Create a workbook with a worksheet
workbook = excelEngine.Excel.Workbooks.Create(1);
//Access first worksheet from the workbook instance.
worksheet = workbook.Worksheets[0];
//Adding text to a cell
worksheet.Range["A1"].Text = "CPS";
worksheet.Range["B1"].Text = "USV";
worksheet.Range["C1"].Text = "Max";
worksheet.Range["D1"].Text = "Mean";
worksheet.Range["E1"].Text = "Date";
worksheet.Range["F1"].Text = "Location";
count++;
}
else
{
SaveAndroid androidOpen = new SaveAndroid();
byte[] byteArray = androidOpen.Open("Radiation_reading.xlsx");
Stream inputStream = new MemoryStream(byteArray);
//Opens the workbook
workbook = application.Workbooks.Open(inputStream);
//Access first worksheet from the workbook instance.
worksheet = workbook.Worksheets[0];
if(worksheet.Range.LastRow <= 1000)
{
//in below, count is number button clicked, if clicked first time, count=2, then position in cell will be in A2,B2 and goes on
worksheet.Range["A" + count].Value2 = 200;
worksheet.Range["B" + count].Value2 = 400;
worksheet.Range["C" + count].Value2 = 400;
worksheet.Range["D" + count].Value2 = 300;
worksheet.Range["E" + count].Value2 = DateTime.Now;
worksheet.Range["F" + count].Value2 = "location";
count++;
}
}
worksheet.UsedRange.AutofitColumns(); // akan fit
//Save the workbook to stream in xlsx format.
MemoryStream stream = new MemoryStream();
workbook.SaveAs(stream);
workbook.Close();
//Save the stream as a file in the device and invoke it for viewing
SaveAndroid androidSave = new SaveAndroid();
await androidSave.SaveAndView("Radiation_reading.xlsx", "application/msexcel", stream, this);
stream.Dispose();
} |
|
if(worksheet.Range.LastRow <= 1000)
{
//in below, count is number button clicked, if clicked first time, count=2, then position in cell will be in A2,B2 and goes on
worksheet.Range["A" + count].Value2 = 200;
worksheet.Range["B" + count].Value2 = 400;
worksheet.Range["C" + count].Value2 = 400;
worksheet.Range["D" + count].Value2 = 300;
worksheet.Range["E" + count].Value2 = DateTime.Now;
worksheet.Range["F" + count].Value2 = "location";
IStyle headstyle2 = workbook.Styles.Add("HeaderStle" + count.ToString());
headstyle2.BeginUpdate();
headstyle2.HorizontalAlignment = ExcelHAlign.HAlignCenter;
headstyle2.EndUpdate();
worksheet.Rows[count-1].CellStyle = headstyle2;
count++;
} |