def CreateSpreadsheet(self, data=None): """ Create spreadsheet from data returned by CalibrationPrompt. Exists mostly to ensure proper xl cleanup by executing in try/finally context. @param data: dict from prompt """ if data is None: if not self._complete: raise DialogIncomplete("Can't create spreadsheet without data.\nNo data given, none generated by dialog.") data = self._data persist = data.get('Persist', False) xl, wb, ws, cells = xlObjs(visible=False) xlctxt = (xl, wb, ws, cells) try: self.PlotData(xlctxt, data) except: print("Error occurred, aborting") raise else: print("Data plotted successfully!") finally: if persist: xl.Visible = True else: wb.Close() xl.Quit()
def __init__(self): self.column = 1 self.xl, self.wb, self.ws, self.cells = xlcom.xlObjs(new=True) self.ws.Name = "Raw" self.sizes = {} self.weights = {} self.tests = [] self.logger = BuiltinLogger(self.__class__.__name__)
def add_to_compiled(self, report): """ @param report: KLAReportFile @type report: KLAReportFile """ xl, wb, ws, cells = xlObjs(report.save_name, visible=False) with HiddenXl(xl, True): self._update_data_sheet(cells, report) self._update_summary_sheet(report)
def analyze_file(self, save=True): """ Analyzing data is ugly. Analyze 'file', where 'file' is a csv file corresponding to a batch data report with KLA data. """ print("Analyzing file:", os.path.split(self.raw_file)[1]) print("Opening new worksheet") xl, wb, ws, cells = xlObjs(self.raw_file, visible=False) with HiddenXl(xl, True): # XXX what if cell not found? do_cell = cells.Find(What="DOPV(%)", After=cells(1, 1), SearchOrder=xlByRows) xcol = do_cell.Column + 1 end_row = do_cell.End(xlDown).Row print("Performing data analysis") self._insert_time_col(ws, cells, xcol) self._insert_ln_col(ws, cells, xcol + 2) print("Creating data plot") # XXX possible in one call? ws.Columns(xcol + 3).Insert(Shift=xlToRight) ws.Columns(xcol + 3).Insert(Shift=xlToRight) named_ranges = _MakeNamedRanges(wb, ws, cells, 2, end_row, xcol - 1) ln_x, ln_y, lin_x, lin_y = named_ranges.get_ranges() chart_name = self.metadata.test_name self.metadata.local_named_ranges = named_ranges # ln v time for specific chart chart = CreateChart(ws, xlXYScatter) CreateDataSeries(chart, ln_x, ln_y) FormatChart(chart, None, chart_name + "-LN(100-DOPV)", "Time(hour)", "-LN(DO PV (%))", True, False) # do v time chart2 = CreateChart(ws, xlXYScatter) CreateDataSeries(chart2, lin_x, lin_y) FormatChart(chart2, None, chart_name + "DO PV", "Time(hour)", "DO (%)", True, False) # uncomment to move to move chart to new sheet # xlLocationAsNewSheet = 1 # chart.Location(1) # uncomment to save in raw data folder # wb.SaveAs(save_name, AddToMru=False) if save: os.makedirs(self.save_path, exist_ok=True) wb.SaveAs(self.save_path + self.save_name, AddToMru=False, FileFormat=xlOpenXMLWorkbook) return ws
def setUp(self): """ @return: @rtype: """ self.data_input = data_input1 self.steps_input = steps_input1 outfile = full_scan_result1 from officelib.xllib.xlcom import xlObjs xl, wb, ws, cells = xlObjs(outfile, visible=False) self.expected_output = wb.Worksheets("Sheet1").UsedRange.Value2 wb.Close(False) xl.Quit()
def plot_fourier(start_temp='37.01', c=HEAT_DECAY_CONSTANT): from officelib.xllib.xlcom import xlObjs start_temp = Decimal(start_temp) tcur = start_temp rt = 25 xl, wb, ws, cells = xlObjs("Book2") cell_range = cells.Range data = [] for s in range(3600): data.append((s, "%.12f" % tcur)) tcur = next_temp(tcur, rt, c) d_len = len(data) d_range = cell_range(cells(1, 4), cells(d_len, 5)) d_range.Value = data
def __init__(self, files=(), savepath='', savename="Compiled KLA Data"): self._data_files = [] self._report_files = [] files = files or () for file in files: self.add_file(file) self._xl, self._wb, self._data_sheet, self._cells = xlObjs() self._summary_sheet = self._wb.Worksheets("Sheet2") self._data_sheet.Name = "Data" self._summary_sheet.Name = "Summary" self._path = savepath or "C:\\Users\\Public\\Documents\\PBSSS\\KLA Testing\\" + pretty_date() + "\\" if not self._path.endswith("\\"): self._path += "\\" self._ln_chart = None self._linear_chart = None self._current_col_data_ws = 1 self._current_row_summary_ws = 2 self._savename = savename
def plot_tests(header, column_data, chart_series_list, header_row_offset=0): """ @param header: iterable of tuples of header data to plot @type header: collections.Sequence[collections.Sequence] @param column_data: iterable of tuples of column data to plot @type column_data: collections.Sequence[collections.Sequence] @param chart_series_list: iterable of ChartSeries instances to plot @type chart_series_list: collections.Sequence[ChartSeries] @param header_row_offset: move the data down by this # of rows @type header_row_offset: int @return: workbook @rtype: officelib.xllib.typehint.th0x1x6._Workbook._Workbook Plot all the tests. Header and column data should correspond. Function isn't private but is probably very hard to use outside of being called automatically by other module functions. """ data_row_offset = len(header) + header_row_offset rows = len(column_data) columns = len(column_data[0]) data_area = cellRangeStr( (1 + data_row_offset, 1), (rows + data_row_offset, columns) ) header_area = cellRangeStr( (1 + header_row_offset, 1), (len(header) + header_row_offset, columns) ) # Because importing xllib requires importing win32com, and # win32com can be very slow to initialize, wait until here to # do the import, so that any errors thrown will abort analysis # before getting to this point. from officelib.xllib.xlcom import xlObjs, CreateDataSeries, HiddenXl from officelib.const import xlLocationAsNewSheet xl, wb, ws, cells = xlObjs(visible=False) with HiddenXl(xl): ws_name = ws.Name cells.Range(header_area).Value = header cells.Range(data_area).Value = column_data chart_map = _prepare_charts(ws, chart_series_list) for series in chart_series_list: # Set these to get proper formula from SeriesRange properties series.sheet_name = ws_name series.series_name = series.series_name % ws_name chart = chart_map[series.chart_name] CreateDataSeries(chart, series.XSeriesRange, series.YSeriesRange, series.SeriesName) for name, chart in chart_map.items(): chart.Location(Where=xlLocationAsNewSheet, Name=name) return wb
def main(self): self.xl, self.wb, self.ws, self.cells = xlcom.xlObjs(self.file_name) with xlcom.HiddenXl(self.xl): self._analyze(self.file_name)