partial void CreateFile(NSObject sender) { var xls = new XlsFile(1, true); xls.SetCellValue(1, 1, "Hello OSX Unified!"); xls.SetCellValue(2, 1, new TFormula("=\"Make sure to \" & \"look at the Windows examples\"")); xls.SetCellValue(3, 1, "for information on how to use FlexCel"); xls.SetCellValue(5, 1, "Concepts are similar, so it doesn't make sense to repeat them all here."); xls.AutofitCol(1, false, 1.2); NSSavePanel SaveDialog = new NSSavePanel(); { SaveDialog.Title = "Save file as..."; SaveDialog.AllowedFileTypes = new string[] { "xlsx", "xls" }; SaveDialog.BeginSheet(Window, (x) => { if (SaveDialog.Url != null) { xls.Save(SaveDialog.Url.Path); } }); } }
/// <summary> /// Draws all of the sections into the file. /// </summary> /// <param name="file">File.</param> /// <param name="dlr">Dlr.</param> private void RenderFile(XlsFile file, DataLogReport dlr) { // Cell coordinates var row = 1; Tuple <int, int> size; file.ActiveSheet = 1; //////////// // SHEET 1 //////////// // Draw the used devices section size = DrawUsedDevices(file, dlr, row, 1); row += size.Item2; row += 2; // Draw the date section size = DrawReportDates(file, dlr, row, 1); row += size.Item2; row += 2; // Draw the device averages size = DrawDeviceAverages(file, dlr, row, 1); row += size.Item2; row += 2; file.AutofitCol(1, size.Item1, false, 1); //////////// // SHEET 2 //////////// row = 1; // Draw raw data file.ActiveSheet = 2; size = DrawAllMeasurements(file, dlr, row, 1); }
/// <summary> /// Draws all of the session's sensor measurement data. This is done in a fairly simple, yet tedious way. Across /// the section header, we will list all of the sensors in the report. The left-most column will show all of the /// sorted dates in all of the sessions. Then, for each sensor, it will list all of its session measurements. When /// a session is complete, we will the bottom of that session's measurement column with a red border. /// </summary> /// <returns>The all measurements.</returns> /// <param name="file">File.</param> /// <param name="dlr">Dlr.</param> /// <param name="row">The x coordinate.</param> /// <param name="col">The y coordinate.</param> protected Tuple <int, int> DrawAllMeasurements(XlsFile file, DataLogReport dlr, int row, int col) { var l = dlr.localization; var sensors = dlr.dataLogResults.Keys; // Coallate data var unsortedMasterDates = new HashSet <DateTime>(); var masterDates = new List <DateTime>(); var sessionBreaks = new Dictionary <int, DateTime>(); var measurements = new Dictionary <GaugeDeviceSensor, Measurements>(); foreach (var sdlr in dlr.dataLogResults) { foreach (var sid in sdlr.Value.sessionIds) { Measurements m; if (!measurements.TryGetValue(sdlr.Key, out m)) { measurements[sdlr.Key] = m = new Measurements() { sensor = sdlr.Key, measurements = new Dictionary <DateTime, Scalar>(), }; } foreach (var dlm in sdlr.Value[sid]) { m.measurements[dlm.recordedDate] = dlm.measurement; unsortedMasterDates.Add(dlm.recordedDate); } var last = sdlr.Value[sid][sdlr.Value[sid].Count - 1].recordedDate; if (sessionBreaks.ContainsKey(sid)) { var dt = sessionBreaks[sid]; if (last > dt) { sessionBreaks[sid] = last; } } else { sessionBreaks[sid] = last; } } } masterDates.AddRange(unsortedMasterDates); masterDates.Sort(); // Draw Header Padding file.SetCellValue(row, col, "", sectionHeaderFormat); var hi = 1; foreach (var key in measurements.Keys) { file.SetCellValue(row, col + hi++, GetHeaderStringFromSensor(ion, measurements[key].sensor), sectionHeaderFormat); } // Draw the master dates list to the file. for (int i = 0; i < masterDates.Count; i++) { var date = masterDates[i]; var format = sessionBreaks.ContainsValue(date) ? sessionBreakFormat : sectionContentFormat; file.SetCellValue(row + i + 1, col, date.ToShortDateString() + " " + date.ToLongTimeString(), format); } // Draw the content for the measurements var mi = 1; foreach (var m in measurements) { for (int y = 0; y < masterDates.Count; y++) { var dt = masterDates[y]; if (m.Value.measurements.ContainsKey(dt)) { var scalar = ion.preferences.units.ToDefaultUnit(m.Value.measurements[dt]); var format = sessionBreaks.ContainsValue(dt) ? sessionBreakFormat : sectionContentFormat; file.SetCellValue(row + y + 1, row + mi, SensorUtils.ToFormattedString(scalar), format); } } mi++; } file.AutofitCol(col, col + mi, false, 1.0); return(new Tuple <int, int>(1 + mi, 1 + measurements.Count)); }