Exemple #1
0
    def 导出到CSV文件(self, srcfilename, tgrfilename, srcsheetnames, rootpath=""):
        xlCSV = 6
        xlCSVWindows = 23
        #self.curApp = win32com.client.GetActiveObject("excel.application")
        self.curApp = ApplicationClass()

        self.curApp = Marshal.GetActiveObject("Excel.Application")

        self.curApp.Application.DisplayAlerts = False
        self.curApp.Application.Workbooks.Open(srcfilename)
        self.curbook = self.curApp.Application.ActiveWorkbook
        # dataPath = self.curbook.path
        # print( dataPath)
        if rootpath == "":
            dataPath = self.curbook.path
        else:
            dataPath = rootpath
        for sheetname in srcsheetnames:
            try:
                fileName = os.path.join(dataPath,
                                        tgrfilename + sheetname + ".csv")
                self.curSheet = self.curbook.Sheets(sheetname).Activate()

                self.curbook.SaveAs(fileName, xlCSV, False)
                print("Save to file Ok:", fileName)
            except:
                print("----Save to CVS Error.", sheetname, fileName)
                # self.curbook.Close()
                pass
            print("导出表页,success.:", end="")
            print(sheetname, " ,in file ", srcfilename)
        self.curbook.Close()
Exemple #2
0
 def 清理CSV文件(self):
     xlCSV = 6
     self.curApp = ApplicationClass()
     self.curApp = Marshal.GetActiveObject("Excel.Application")
     # self.curApp = win32com.client.GetActiveObject("excel.application")
     self.curApp.Application.DisplayAlerts = False
     self.books = self.curApp.Application.Workbooks
     for book in self.books:
         filename = book.Name
         extension = filename[-4:]
         extension = extension.upper()
         if extension == ".CSV":
             pass
             book.Close()
 def 合并Xls(self, fileName):
     xlCSV = 6
     xlOpenXMLWorkbook = 51
     xlExcel12 = 50
     self.curApp = ApplicationClass()
     self.curApp = Marshal.GetActiveObject("Excel.Application")
     self.curApp.Application.DisplayAlerts = False
     self.books = self.curApp.Application.Workbooks
     newbooks = self.books.Add()
     newbooks.SaveAs(fileName, xlExcel12)
     AfterSheet = newbooks.Sheets(1)
     for book in self.books:
         filename = book.Name
         extension = filename[-4:]
         extension = extension.upper()
         if extension == ".CSV":
             pass
             book.Sheets(1).Move(AfterSheet)
     newbooks.Save()
def WriteExcel(patient_name, beam_set_name, perturbation_settings, dvhs_pert,
               stat_pert, bins, fractions, colors):
    print("WriteExcel")
    print(fractions)
    try:
        excel = ApplicationClass(Visible=True)
        workbook = excel.Workbooks.Add(XlWBATemplate.xlWBATWorksheet)
        worksheet = workbook.Worksheets[1]
        current_cell = worksheet.Cells(1, 1)
        rois = dvhs_pert.itervalues().next().keys()
        charts = CreateCharts(worksheet, current_cell, len(rois) + 1)
        current_cell = current_cell.Cells(1, 10)
        current_cell = WritePatientInfo(worksheet, current_cell, patient_name,
                                        beam_set_name)
        current_cell = WritePerturbationSettings(worksheet, current_cell,
                                                 perturbation_settings)
        current_cell = WriteDoseStatistics(worksheet, current_cell, stat_pert,
                                           fractions)
        current_cell = WriteIndividualCurves(worksheet, charts[1:],
                                             current_cell, dvhs_pert, bins,
                                             colors)
        dvhs_minmax = GetMinMaxCurves(dvhs_pert, bins)
        current_cell = WriteMinMaxCurves(worksheet, charts[0], current_cell,
                                         dvhs_minmax, bins, colors)

    finally:
        if charts:
            for c in charts:
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(c)
        if worksheet:
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(
                worksheet)
        if workbook:
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(
                workbook)
        if excel:
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(excel)
        System.GC.WaitForPendingFinalizers()
        System.GC.Collect()
    def 合并2Xls(self, xlsfileName, srcFilenames=[]):
        xlCSV = 6
        xlOpenXMLWorkbook = 51
        xlExcel12 = 50
        self.curApp = ApplicationClass()
        self.curApp = Marshal.GetActiveObject("Excel.Application")
        self.curApp.Application.DisplayAlerts = False
        self.books = self.curApp.Application.Workbooks
        newbooks = self.books.Add()
        newbooks.SaveAs(xlsfileName, xlExcel12)
        AfterSheet = newbooks.Sheets(1)

        for srcfile in srcFilenames:
            try:
                os.startfile(srcfile)
            except:
                pass
            book = self.curApp.Application.ActiveWorkbook
            rootpath, filename = os.path.split(srcfile)
            if filename == book.Name:
                book.Sheets(1).Move(AfterSheet)
        newbooks.Save()
Exemple #6
0
        current_cell.Cells(2, 1),
        current_cell.Cells(1 + data_array.GetLength(0),
                           data_array.GetLength(1)))
    data_range.Value = data_array

    return current_cell.Cells(nrows + 3, 1)


# Execution starts here
try:
    case = get_current("Case")
    patient = get_current("Patient")
    plan = get_current("Plan")
    beam_set = get_current("BeamSet")

    excel = ApplicationClass(Visible=True)
    workbook = excel.Workbooks.Add(XlWBATemplate.xlWBATWorksheet)
    worksheet = workbook.Worksheets[1]
    current_cell = worksheet.Cells(1, 1)
    current_cell = current_cell.Cells(1, 10)
    current_cell = WritePatientInfo(worksheet, current_cell,
                                    patient.PatientName,
                                    beam_set.DicomPlanLabel)
    current_cell = WriteDoseStatistics(worksheet, current_cell, plan, patient)

except Exception as e:    \
        wait_user_input("Exception thrown:" + str(e))

finally:
    if worksheet:
        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(worksheet)
Exemple #7
0
    string = url.split('/dir/')[1].replace('@','').replace(',15z','')
    cords = [[cor for cor in item.split(',')] for item in string.split('/')]
    
    for item in cords:
        loc = create_cord(float(item[0]),float(item[1]))
        locs.append(loc)
    
    return locs

fs = ds.FileSystems[0]
node = fs['[email protected]_14-11-54_SW (1) - ORIGINAL.xlsx']
data = node.read()
tempf = tempfile.NamedTemporaryFile()
tempf.write(data)

excel = ApplicationClass()
ex = excel.Workbooks.Open(tempf.name)
ws = ex.Worksheets[4]
rows = ws.Range['A2','DM22']

for item in range(1,ws.Rows.Count+1):
    # Instantiate Class
    j = Journey()
    j.Name.Value = rows.Cells(item,1).text
    j.Deleted = DeletedState.Intact
    
    #Start and End time
    j.StartTime.Value = TimeStamp.FromUnixTime(calendar.timegm(time.strptime(rows.Cells(item,4).text, "%Y-%m-%dT%H:%M:%SZ"))+25200)
    j.EndTime.Value = TimeStamp.FromUnixTime(calendar.timegm(time.strptime(rows.Cells(item,8).text, "%Y-%m-%dT%H:%M:%SZ"))+25200)
    j.FromPoint.Value = create_cord(float(rows.Cells(item,6).text),float(rows.Cells(item,7).text))
    j.ToPoint.Value = create_cord(float(rows.Cells(item,10).text),float(rows.Cells(item,11).text))