Open plaintext files like python files - google-colaboratory

If you tinker a lot with Google Colab maybe you want to edit some .txt files or view a .csv file or any other kind of .csv files, you can already open python files.
If you go to the file directory listing and click
Just click on the file you want to open, and you open a new tab
However if this file is not a python file, you simply download it, is there a way to view the file in browser?

I made a library to show files easily in Colab.
!pip install kora
For any text file, you can use bat which provide syntax highlight. See documentation
import kora.install.bat
!bat sample_data/README.md
For a csv, you can use google.colab.data_table, which I simplify calling it a bit.
import pandas as pd
import kora.data_table
pd.read_csv('sample_data/california_housing_test.csv')
For a json file, it can make a collapsible display
from kora.json import render
render('sample_data/anscombe.json')
See all 3 examples in this notebook.

Related

How to open a program and import multiple files?

I use a program which accepts only a single file. I can either click File->Import from Menu or Ctrl+I to upload a file. Then, a windows pops up to choose my choice of file. I need to change the data type to Import so that I can see all files. Double-clicking on a file, I am back to my program and see some outputs, analysis report and plots. I click on 'Graph' tab and in there I click on export graph. Then, a windows pops up and I need to click on save to save the graph.
My Expectation is to export such plots for hundreds of different files from same path. How should I perform this?

how do I use my local drive folder as data source in datagrip?

Using Datagrip,
I wanna write sql code and take some aggregated data from my csv file saved in my local drive.
How do I point my folder as datasource in datagrip and import csv to there to run sql code?
I have csv files in my local drive but don't know how to set my folder as data source and import my csv files as tables to be used.
You can right click on the schema and click on import data from file like below. You will see a window pop up where you specify separators, headers, etc along with a preview.

Excel crashes after append

I am using openpyxl to automatically append data. My excel file has picture widgets(Text box) like shown below (highlighted). But the picture widgets are deleted after append. Also, I get the error: "Removed Feature: Named range from /xl/workbook.xml part (Workbook)", "Removed Part: /xl/drawings/drawing3.xml part. (Drawing shape)". Can anyone please let me know how to resolve this.
Thanks in advance!
Openpyxl can't read images directly (documentation: https://openpyxl.readthedocs.io/en/default/usage.html). There are some types of image it won't save at all.
Warning:
openpyxl does currently not read all possible items in an Excel file so images and charts will be lost from existing files if they are opened and saved with the same name.
However, there are some nice solutions on this old post, even though openpyxl functionality has changed since then. Particularly, installing Pillow via pip may help you: Images dissapear in excel documents when copying them with python
The alternative is to use libraries other than openpyxl. I have previously had cause to use openpyxl for some functions, and then stitch final image-containing documents together with win32com on Windows, for example.

Edit source code of Impress odp file

I want to edit the source code of an Impress file (.odp) but when I open it is just machine coded.
I want to do it because when I converted files from PowerPoint to an Impress File some parts got mixed up. Like for example footer and numbering can't be changed globally. So by editing the source code, I hope to be able to use find/replace in a Text Editor.
LibreOffice formats are zipped archives primarily containing XML files. So unzip the .odp and then edit content.xml.
When finished, zip it back up, making sure to zip it from the correct directory (the one that contains content.xml).
Documentation: https://help.libreoffice.org/Common/XML_File_Formats#XML_file_structure.
If you are using a Mac do the following:
Change the .odp extension to .zip by manually clicking the icon and renaming the file
Unzip the file using something other than the standard Archiver (I used Keka)
You will see the folder of contents including the content.xml which you can easily edit now
Crucial: Go into the directory with your separate files, select all the files then hit 'compress' from the options menu when you right click
Next, rename the .zip to .odp and the file will open successfully
I found that if you don't do option 4 above exactly then the file is slightly different and won't open due to a corruption message.

VBE import code module is coming through as the wrong type

I have downloaded some code modules (.cls files) from a Git Repository. When I import (some, not all) into the VBE (File: Import), it imports it as a 'Standard' module (as if it were a .bas file).
If I open the cls file in Notepad++, copy the entire contents to a new file and save as "a.cls" then I can import and it correctly is interpreted as a new Class.
I am totally confused and with lots of code modules to go through, I don't want to have to manually re-save each one.
Does anyone have any ideas?
EDIT
I am importing in to Excel 2016 (64-bit) on Windows 10. I don't know the Excel version that the files were created in.
The files are at: https://github.com/ckuhn203/VBEX/tree/master/src
As an example: Monadic.cls imports as a standard module file.
This is because the files have a single LF for the line break.
MS Office expects code files to use CRLF. Because it doesn't find it, it fails to read the attributes that declare the file is a class.
See e.g. Windows command to convert Unix line endings? to mass-replace the line breaks.