public void SavePricing() { //Create an instance of ExcelEngine. using (ExcelEngine excelEngine = new ExcelEngine()) { //Set the default application version as Excel 2013. excelEngine.Excel.DefaultVersion = ExcelVersion.Excel2013; //Create a workbook with a worksheet IWorkbook workbook = excelEngine.Excel.Workbooks.Create(1); workbook.Version = ExcelVersion.Excel97to2003; //Adding text to a cell for (int y = 0; y < ((List <PriceRange>)Application.Current.Properties["Prices"]).Count(); y++) { PriceRange thisPrice = ((List <PriceRange>)Application.Current.Properties["Prices"]).ElementAt(y); workbook.Worksheets.Create(thisPrice.GetName()); IWorksheet worksheet = workbook.Worksheets[y + 1]; worksheet.SetValue(1, 1, "Name"); worksheet.SetValue(2, 1, "Log Size"); worksheet.SetValue(1, 2, thisPrice.GetName()); worksheet.SetValue(2, 2, thisPrice.GetLength().ToString()); worksheet.SetValue(3, 1, "Size"); worksheet.SetValue(3, 2, "Price"); worksheet.SetValue(3, 3, thisPrice.GetBrack().Count.ToString()); for (int x = 0; x < thisPrice.GetBrack().Count; x++) { worksheet.SetValue(4 + x, 1, thisPrice.GetBrack().ElementAt(x).Key.ToString()); worksheet.SetValue(4 + x, 2, thisPrice.GetBrack().ElementAt(x).Value.ToString()); } worksheet.Range["A1:A3"].CellStyle.Locked = true; worksheet.Range[3, 2].CellStyle.Locked = true; } workbook.Worksheets[0].Remove(); //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 Xamarin.Forms.DependencyService.Get <ISave>().Save("Pricings.xls", "application/msexcel", stream); } }
private void PopList(int select) { //Fills list of prices if (select > -1) { List <string> ArrayList = new List <string>(); PriceRange ThisPrice = ((List <PriceRange>)Application.Current.Properties["Prices"]).ElementAt(select); SortedList <double, double> brack = ThisPrice.GetBrack(); for (int x = 0; x < brack.Count(); x++) { if (x == brack.Count() - 1) { ArrayList.Add(brack.ElementAt(x).Key + "cm " + AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("OrLarger") + "\t\t\t\t" + AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Price") + ": " + brack.ElementAt(x).Value + ((int)Application.Current.Properties["Currenselect"] == -1 ? "$" : ((List <(string, double)>)Application.Current.Properties["Currenlist"]).ElementAt((int)Application.Current.Properties["Currenselect"]).Item1) + "/m\xB3"); } else { ArrayList.Add(brack.ElementAt(x).Key + "cm to " + brack.ElementAt(x + 1).Key + "cm" + "\t\t\t\t" + AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Price") + ": " + brack.ElementAt(x).Value + ((int)Application.Current.Properties["Currenselect"] == -1 ? "$" : ((List <(string, double)>)Application.Current.Properties["Currenlist"]).ElementAt((int)Application.Current.Properties["Currenselect"]).Item1) + "/m\xB3"); } } NameOfPrices.Text = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Name") + ": " + ThisPrice.GetName() + AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("LogLength") + ": " + ThisPrice.GetLength().ToString() + "m"; PriceArray = ArrayList.ToArray(); PriceList.ItemsSource = PriceArray; PriceList.HeightRequest = (40 * PriceArray.Length) + (10 * PriceArray.Length); } }