I wonder if there are any text properties that you could use to help you do this.
For example, based on a quick glance, there are much more vertical lines in the text (l, j, k, m, n, etc.) than horizontal lines, so maybe you can start with this.
But even finding them is not easy, you need to use some kind of filter, for example, Sobel or Prewitt . They have horizontal and vertical versions, see here for more information.
Of course, the vertical / horizontal rows of an Excel spreadsheet will be the strongest edges, so you have to ignore them and look only at the text.
Alternative: Can't you just give the user a simple way to rotate images, such as arrows in the Windows Picture viewer, or just show 4 thumbnail thumbnails that they can click on. You may need to cache 4 versions (if you're spinning), so it's fast, but only if speed proves to be a problem?
Matt warren
source share