Sunday, July 12, 2020

Reading Office documents, Word (.docx) etc. in C#

If you have a requirement of manipulating office documents programmatically in a platform independent way, i.e. with out office interop assemblies, NPOI in one of the best choices available.

  


NPOI is .NET avatar of ever popular Apache POI project. It continues to be open source library for manipulating any Office file formats. If you have ever used Apache POI's Java implementation, NPOI would be straight forward.

For example if you want to print the entire text in a docx file, below is a such an example function :


        public static void PrintAllText(string path)
        {

            Stream is1 = new System.IO.FileStream(path, FileMode.Open, FileAccess.Read);
            XWPFDocument doc = new XWPFDocument(is1);
            int i = 0;

            while (i < doc.BodyElements.Count)
            {
                var runText = (doc.BodyElements[i] as XWPFParagraph).Text;
                Console.WriteLine(runText);
                i++;
            }

        }

Another example if you want to read a word and get all the images from a .docx file, below is one such sample

        public static void ReadImages(string filePath)
       {
            string path = filePath;
            Stream stream = new System.IO.FileStream(path, FileMode.Open, FileAccess.Read);
            XWPFDocument doc = new XWPFDocument(stream);
            int i = 0;
            var list = doc.AllPictures;
            while (i < list.Count)
            {
                XWPFPictureData data = list[i];
                Console.WriteLine("Name" + data.FileName);
                Console.WriteLine("Details" + data.ToString());
                i++;
            }
       }


Here are some of the important links for NPOI

  1. NPOI Home Page
  2. Git Page

Saturday, July 11, 2020

Kids Learning Scratch

Kids are adapting to new age technologies faster than anytime in history. Computer education is not left behind in this trend. Easy access to devices (laptop's , tablets etc.) have revolutionized how early kids are starting with computer education and programming fundamentals.

To balance and meet this demand, there are several platforms which provide programming platforms specially developed and designed for early boomers. Scratch is one such platform. I was amazed by how simple the experience to engaged young kids and introduce them to concepts like Controls, Events, Loops etc.

Here is the one such video of Ianshi teaching her friends of similar age an introduction to Scratch.



Saturday, May 4, 2019

Windows Bluetooth : Mystery of Auto Connect

I use Windows10 on my personal machine and one fine day found myself struggling with Bluetooth connectivity on it.






 The device in question (external speakers) still shows up in the paired device section but would not connect automatically, even when the speaker is switched on in range of Bluetooth of Windows 10 machine.



Fed up with manually connecting speaker every single time, tried to look up on Windows trouble shooting page and found nothing in this regards.

From all the solutions mentioned in net, the below one works for me

1. Press Windows Key + R Key.
2. Type services.msc and scroll down to Bluetooth Support Service in the list.
3. Right click on it and select Properties.
4. Set up Start up type to Automatic from the dropdown list.


And voila speakers connect automatically from here on !!

 

Tuesday, October 23, 2018

Finally Oreo is here for A9 Pro devices

Samsung has finally released the Android OREO update for Samsung A9 Pro devices.







Why is this important you ask ? Well for one it has been released a bit earlier than expected than Samsung earlier estimates which slated this release for December 2018. No pun intended on "bit earlier" part, Samsung is notoriously slow in release updates. Secondly, this might well be the last update A9 Pro might receive, yes Android Pie is not guaranteed for this device, so you better like since you are going to be stick with it for a while.

Getting back to update, update is roughly 1.3GB in the OTA mode. Get a wifi and make some space on your devices guys.






I heard some reviews of updates going wrong and users loosing all there data, gladly nothing of this sort happened on my device and update for largely smooth. Just ensure you have enough juice(battery), stable wifi and sufficient space in phone.

From the early reviews

1. First and foremost I finally do not need external call recorders. While the experience is still tad shady in comparison to other OS like MI, but still a relief from using external call recorders. You can access from settings in Phone application.

2. Camera UI has changed. I noticed some distortion in still images, not sure if its the update though. Video quality has for sure got better.

3. RAM management is bit unpredictable, guess the ease and nimbleness of switching apps has been traded for better battery management.

4. Secure folders app is now available to store all those important personal documents.

5. Other features like Samsung Pay etc are available out of box, not sure if they are functional in Indian stores thought.

6. Google Assistant has improved by notches and really works. Be sure to customize it to your voice samples.

After the update your phone would be Android 8.0 and Samsung User Experience version 9.0


Thursday, May 10, 2018

The Next Wave of AI : Google Duplex

Recently demo'ed at Google annual event is the new product named Google Duplex. Duplex takes the digital assistance a level ahead, by not using APIs or application flows to do day to day jobs but by actually making phone calls.



Whats more interesting is how close attention was given to human interaction, the ahan and hmms are just some of the stop gap's and linguistic fillers it uses to fool the humans on other side in believing they are speaking to real humans.


Here is the link to full demo




Full geeky points on Tech front, but what about ethics ? Is it fair for AI to fool humans in an interaction ?



Some of the things to worry about how easily this technology can be used to spam people with voice calls and unlike spam of emails this one would not be easier to catch. Funnily Google invested more in making in harder to catch duplex rather than voice interaction itself.

Start preparing you list of trick questions :)

Thursday, February 15, 2018

Excel Hacks : How to copy data in row of excel into a column (Transpose)

Working on a data science project makes you play with diverse data sources in the most crazy way you can imagine.

While aligning the data programmatically via data frames in the most sane way to do, but sometime you just want to check the data in a quick dirty way via the all familiar Excel.

Aligning the data in one format (vertically or horizontally) can be a challenge though, since there is no universal rule for defining what should be on X axis and what should be on Y. There is one trick though you can use to quickly transpose the numbers either way (vertical to horizontal or vice versa)

1. Copy the data, say which is present in the horizontal format.



2. Go the sheet now where you want to paste this in the vertical format, right click on cell where you want data to start from, right click, and from Paste options choose Transpose option.

Paste Options menu

3. You will have the data in the format you want.






Tuesday, February 6, 2018

Having multiple rows in Bookmarks Toolbar in Firefox

I have recently been bookmarking a lot, I guess that happens when teams are busy doing surveys and are not quite sure of right direction but have tonnes of material to refer to, or probably you are picking a domain, worst still may be both :)

Anyways thing is you may end up with too many bookmarks and folders to be contained in a single line. Is there a way you can still see all your bookmarks and folders?

Just discovered this wonderful plugin, which basically does css adjustments allowing bookmark line to span to multiple lines.

So this




Turns into



So if you are on firefox, do give a try for sure. Here is the link
https://addons.mozilla.org/en-US/firefox/addon/multirow-bookmarks-toolbarplus/

Merging and Splitting PDF files

We all use and rely on PDF's. There are occasions though when you want to edit certain portions of a pdf and merge the edited version ba...