Convert this in excel sheet

Reading File
Reading File
Browsing Directory

~/

Browsing Directory

~/attachments/d7c5797c-42fd-42eb-97ce-a7dab7ac8674/

Reading File
Reading File
Running Command

mkdir -p "/tmp/workspace/ug-iii-second-lecture/src" "/tmp/workspace/ug-iii-second-lecture/output" && python -c "import pdfplumber; p='/tmp/workspace/attachments/d7c5797c-42fd-42eb-97ce-a7dab7ac8674/UG III second lecture.pdf'; pdf=pdfplumber.open(p); print('pages',len(pdf.pages)); [print('---PAGE',i+1,'---\\n'+(page.extract_text() or '')[:5000]) for i,page in enumerate(pdf.pages)]"

Reading File
Running Command

python - <<'PY' import pdfplumber p='/tmp/workspace/attachments/d7c5797c-42fd-42eb-97ce-a7dab7ac8674/UG III second lecture.pdf' out='/tmp/workspace/ug-iii-second-lecture/src/extracted.txt' with pdfplumber.open(p) as pdf: text='\n'.join(page.extract_text(x_tolerance=1,y_tolerance=3) or '' for page in pdf.pages) open(out,'w',encoding='utf-8').write(text) with pdfplumber.open(p) as pdf: print(pdf.pages[0].extract_tables()) print('written',len(text)) PY

Running Command

python - <<'PY' import pdfplumber from openpyxl import Workbook, load_workbook from openpyxl.styles import Font, PatternFill, Alignment, Border, Side from openpyxl.worksheet.table import Table, TableStyleInfo from openpyxl.utils import get_column_letter from pathlib import Path pdf_path=Path('/tmp/workspace/attachments/d7c5797c-42fd-42eb-97ce-a7dab7ac8674/UG III second lecture.pdf') out=Path('/tmp/workspace/ug-iii-second-lecture/output/UG_III_Second_Lecture_Schedule.xlsx') with pdfplumber.open(pdf_path) as pdf: raw=pdf.pages[0].extract_tables()[0] rows=[] for r in raw: if len(r)>=5 and r[1] and str(r[1]).strip().isdigit(): no=int(str(r[1]).strip()) topic=(r[2] or '').strip() date=(r[3] or '').strip() faculty=(r[4] or '').strip() # repair a split row created by the source PDF's narrow date cell if no==40: topic='Counsel and communicate to patient with empathy regarding lifestyle changes in atheroscelerosis/post coronary syndromes(IM2.24) AETCOM(4.18)' date='8/8' rows.append([no,topic,date,faculty]) assert len(rows)==80, len(rows) assert [r[0] for r in rows]==list(range(1,81)) wb=Workbook() ws=wb.active ws.title='Lecture Schedule' ws.sheet_view.showGridLines=False ws.freeze_panes='A2' headers=['No.','Topic / Competency','Date','Faculty'] ws.append(headers) for row in rows: ws.append(row) navy='1F4E78'; light='D9EAF7'; alt='F3F7FB'; white='FFFFFF' header_fill=PatternFill('solid',fgColor=navy) for cell in ws[1]: cell.font=Font(name='Arial',size=11,bold=True,color=white) cell.fill=header_fill cell.alignment=Alignment(horizontal='center',vertical='center',wrap_text=True) ws.row_dimensions[1].height=28 thin=Side(style='thin',color='B7C9D6') for row in ws.iter_rows(min_row=2,max_row=ws.max_row,min_col=1,max_col=4): for c in row: c.font=Font(name='Arial',size=10) c.alignment=Alignment(vertical='top',wrap_text=True) c.border=Border(bottom=thin) row[0].alignment=Alignment(horizontal='center',vertical='top') row[2].alignment=Alignment(horizontal='center',vertical='top') if row[0].row%2==1: for c in row: c.fill=PatternFill('solid',fgColor=alt) ws.row_dimensions[row[0].row].height=30 ws.column_dimensions['A'].width=8 ws.column_dimensions['B'].width=88 ws.column_dimensions['C'].width=14 ws.column_dimensions['D'].width=28 ws.auto_filter.ref=f'A1:D{ws.max_row}' tab=Table(displayName='LectureSchedule',ref=f'A1:D{ws.max_row}') tab.tableStyleInfo=TableStyleInfo(name='TableStyleMedium2',showRowStripes=True,showColumnStripes=False) ws.add_table(tab) ws.sheet_properties.pageSetUpPr.fitToPage=True ws.page_setup.orientation='landscape'; ws.page_setup.fitToWidth=1; ws.page_setup.fitToHeight=0 ws.print_title_rows='1:1' ws.sheet_properties.outlinePr.summaryBelow=True notes=wb.create_sheet('Notes') notes.sheet_view.showGridLines=False notes['A1']='Source' notes['B1']='UG III second lecture.pdf' notes['A2']='Records extracted' notes['B2']=80 notes['A3']='Extraction note' notes['B3']='Entry 40 was split by the PDF layout and reconstructed as a single topic. Dates are retained as displayed in the source.' for row in notes.iter_rows(min_row=1,max_row=3,min_col=1,max_col=2): for c in row: c.font=Font(name='Arial',size=10,bold=(c.column==1)) c.alignment=Alignment(vertical='top',wrap_text=True) notes.column_dimensions['A'].width=22; notes.column_dimensions['B'].width=115 for r in range(1,4): notes.row_dimensions[r].height=32 wb.save(out) # validate check=load_workbook(out, data_only=False) assert check['Lecture Schedule'].max_row==81 assert check['Lecture Schedule']['A81'].value==80 assert check['Lecture Schedule']['B41'].value.startswith('Counsel and communicate') print(out, out.exists(), out.stat().st_size) PY

Converted the PDF lecture schedule into a formatted Excel workbook with 80 entries, filters, frozen header row, and a notes sheet.

UG III Second Lecture Schedule

Spreadsheet · XLSX

Normal excel no colour coding default setting

Reading File
Browsing Directory

~/

Browsing Directory

~/ug-iii-second-lecture/

Reading File
Running Command

python - <<'PY' from openpyxl import load_workbook, Workbook from openpyxl.styles import Font, Alignment from pathlib import Path src=Path('/tmp/workspace/ug-iii-second-lecture/output/UG_III_Second_Lecture_Schedule.xlsx') out=Path('/tmp/workspace/ug-iii-second-lecture/output/UG_III_Second_Lecture_Schedule_Plain.xlsx') old=load_workbook(src, data_only=False) ows=old['Lecture Schedule'] wb=Workbook() ws=wb.active ws.title='Lecture Schedule' # Copy values only to retain default Excel appearance and no colour coding for row in ows.iter_rows(values_only=True): ws.append(list(row)) for cell in ws[1]: cell.font=Font(name='Calibri', size=11, bold=True) cell.alignment=Alignment(horizontal='general', vertical='bottom') for row in ws.iter_rows(min_row=2): for cell in row: cell.font=Font(name='Calibri', size=11) ws.column_dimensions['A'].width=8 ws.column_dimensions['B'].width=88 ws.column_dimensions['C'].width=14 ws.column_dimensions['D'].width=28 # Deliberately no fills, table styles, filters, borders, or colour formatting. wb.save(out) check=load_workbook(out) assert check.sheetnames == ['Lecture Schedule'] assert check['Lecture Schedule'].max_row == 81 assert check['Lecture Schedule']['A81'].value == 80 assert check['Lecture Schedule'].auto_filter.ref is None print(out, out.exists(), out.stat().st_size) PY

Plain Excel version with default formatting and no color coding:

UG III Second Lecture Schedule Plain

Spreadsheet · XLSX

This is a shared conversation. Sign in to Orris to start your own chat.