Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import up-to-n-rows from text

Tags:

excel

When importing from text to Excel, I have seen many tips to overcome Excel's limit. My problem is different, I want to set a (small) limit myself, because what I want is to preview the data in some huge files. Therefore I need to ask Excel to import the data up to some number of rows (say 100 rows, or eventually setting any other limit, such as total count of bytes to read from the input file, or total cell count, anything).

I know a way to create a query connection that drops some columns, but what I want is a way to truncate while preserving all the columns.

Besides, VBA is not an option. I repeat the operation many times with different files and formats, I just need a handy trick to preview quickly with Excel using "Import From Text".

Any tips? Thanks is advance.

like image 630
A.S.H Avatar asked Oct 31 '22 00:10

A.S.H


1 Answers

One simple approach could be to use PowerShell to create previews of the files.
For example executing the following PoSh pipeline in the folder with some big CSV files (but could be any text files) would create rather small preview files of them.

Get-ChildItem *.csv | % { 
    $fn = $_.BaseName + '.preview' + $_.Extension;
    $_ | Get-Content -First 100 | Out-File $fn 
}

enter image description here

like image 197
DAXaholic Avatar answered Nov 15 '22 06:11

DAXaholic