Referencing cells in XWPFTable with Apache POI - apache

I'm writing a docx parser with Apache's POI library. I'm having some trouble understanding how cells are referenced within a XWPFTable. Can someone explain how the referencing is done if non uniform tables are presented (ie two columns with different number of rows).

POI XWPF will give you the cells in the order that Word has stored them in the file. It's as (deceptively!) simple as that...
To check what word does, one option it just to use POI and see what you get. The other is to unzip the word file - a .docx is simply a special zip of xml files. Look at the document XML and see how Word has decided is the best way to store your complex set of table cells. Then, ask POI for them, and you should get the same ordering!

Related

How to automatically convert text-based numbers to numbers in several files?

I have 1000 files in Excel format (Excel 2010) and each file contains 7 sheets with data.
This is an example for Excel sheet.
Is there a way to automatically convert the numbers that are stored as text to numbers, without affecting the actual text data? (maybe by VBA macros ? but I am a beginner in VBA code)
I can give you an algorithm, but I don't have time to write the entire code. I would write it in a seperate workbook, for repeatability. You can then either hardcode the 7 file names, or you can make an input for file name (the latter is a bit more flexible, if you need to use it for more files later).
Open a file
Loop all sheets
Loop all cells
If IsNumeric(Cell.Value) > Change format
You should be able to Google your way to the separate parts. Once you have some actual code, you can ask for more help on StackOverflow.

Access to Word Template

I am having issues figuring out the best way to do this:
I have a word template for an interview pre-night. What I need to do is fill out the word template with the interviewer and the people who are interviewing them. There will always be 1 interviewee but up to 12 interviewers. The part giving me issue is that there will not always be 12 interviewers so the area that the data is moved to needs to be dynamic. Should I create a table or bookmarks in Word and use VBA to move the data, or design the report in Access? Thanks for your help!
I am going to assume that what you are trying to do is complicated enough that "mail merge" won't work for you.
It really depends on whether you need the end result to be a Word document or an Access report. Both easily convert to PDF for document archiving. If you prefer to work with Word, add the key fields into your document with all the formatting necessary and then use VBA to do a search replace.
Two ways you could go about dealing with the 1-12 interviewers issue:
Use VBA to create one long segment containing all interviewers as a
single "field".
Add 12 sets of key fields and use search/replace
(through VBA of course not manually) to fill in the exiting
interviewer info and delete the key fields for the non-existing ones.

Mass Excel hyperlinks

I've looked around and can't seem to find any help for what I am looking to do.
I have a document that I am using to record data related to repairs and such on machines.
All of my entries are done in a numeric order.
I have to scan hard copies in and hyperlink to them from the excel sheet.
All the files are named to me in a numerical order as well that matches the number in column A.
Is there a way to do this as a formula?
You can use the HYPERLINK formula. The 1st parameter allows you to dynamically build up the URL to point to, so if you say you have the correct numbers already in a column, you can use that to build the URL. Provided the URL for each scanned document can uniquely be derived using only that number, of course.
If the scanned documents are on the web, then you can use e.g.:
=HYPERLINK("https://www.myserver.com/scans/"&A4&".pdf","Scan nr. "&A4)
If they're on your own computer (or on a network drive), then you can use e.g.:
=HYPERLINK("file:///D:/scans/"&A4&".pdf","Scan nr. "&A4)
--- EDIT ---
As Cyril pointed out, you can also just use e.g.:
=HYPERLINK("D:\scans\"&A4&".pdf","Scan nr. "&A4)
which makes it a bit more readable. Also note that Excel really likes to warn you when using these types of links ;)

Automated formatting CSV files using an Add-In in Excel 2010

I have a C program that generates CSV files as output.
For example - I have 12 CSV files; one for each month. First column is Employee Name and Second column is their respective salaries. Assume there are 10 employees.
I want to format the 'salaries'column such that if a cell has a value over 10,000, the text should become green. Else it should remain blue. I have been able to do this using VBA for one file by adding a Command Button in the file and writing a small script.
However the issue is, every time I run my C code, it will generate a new set of CSVs; overwriting the existing ones. Besides, I want to apply such formatting to other CSV files I intend to generate.
I read that a .xla Add-In (which can exist on its own unlike embedded VBA macros in an Excel sheet) might be the solution.
I have 2 questions -
1. Is it possible to do with Add-Ins?
2. If yes, then I wanted to create a single batch file which would first generate the CSVs, and then run the Add-In on it. Is that possible too?
Thank You.

Word VBA - Matching large selecting of text based keys with data. Embedded resource/text?

I have a pretty complex VBA plugin for Word written that automatically creates a report for me, using XML input, cycling through the X objects within the report to create the output. It is currently embedded into a Word Template file .DOCM.
I need to insert into the report a static list of text, based on the name of the item within the XML. For example, within my XML I have entries with a name BLAH1, BLAH2, BLAH3. Every time I see BLAH1, I need to match it with the static INSERT1, and BLAH2 match it with INSERT2, etc.
This seems simple enough, but her lies the problem...
It appears there are no Hashmap's in VBA without requiring external libraries, which I can't really rely on, since I can't install items on the machines where this will be running. As a result I can't store this reference data in a Hashmap as far as I can tell.
I can't seem to concatenate more than about 20 lines of strings together without hitting a max within VBA, and just parsing the chunk of text for what I need since there are about 1500 "lines" in my reference data, which greatly exceeds 20.
I also haven't found a way to embed a text, or any other type of file to hold this information within the file, and then parse the data.
I really would like to have everything within the single template file, without requiring additional text or other files to be bundled with the document. If there is no other option, I will go that route, but I wanted to see what create ideas people at Stackoverflow might have first ;-)
Have you considered using Word's Document Variables? They are name/value pairs stored invisibly within the document. (ActiveDocument.Variables("BLAH1").Value = "INSERT1" to create one, debug.print ActiveDocument.Variables("BLAH1").Value to retrieve a value (you have to use an error handler to detect non-existent indices if you go that route). Word can store (at least) hundreds of thousands of these things).