Excel formula to output line breaks to word document - excel

I have an Excel spreadsheet that is linked to a Word document.
This word document is a letter.
I have a field in Excel that is optional for the user to enter data into, but if something is present then it needs to be included into the letter.
I can do all that just fine, but this additional data needs to be in its own paragraph on the Word document. Hence some new lines need to be introduced to separate this new paragraph from the rest of the text, but also for these lines not to be present if the data isn't present.
On my Excel worksheet I have discovered this is how to do this:
=IF(B36="","",CHAR(10)&B36&CHAR(10))
However, on the word doc, this outputs as:
I do not want the " characters, but need the line breaks that it gives.
Entering the line breaks on the word doc beforehand is not an option, as I say, they need to NOT be present if this data is not present.
The output to Word is perfect if no data is present in the field. No line breaks and no " characters.

char(10) is the number for new line in Excel, char(11) is the number for new line in Word.
Was simply a case of replacing 10 with 11
=IF(B36="","",CHAR(11)&B36&CHAR(11))
Which gives the desired effect:

Related

How does ms word vba detect the end of a paragraph

I converted an html text into a docx document using several different online converters.
Then I analysed the number of paragraphs using an Excel vba macro which opens the document and examines it. Supplied with an original docx document (ie one not converted from another format) this macro always gives the correct number of paragraphs.
Only one converter yielded a docx from which the number of paragraphs could be determined. All the others simply said there was a single paragraph with hundreds of words in it.
Somehow the html to docx converters are missing something. What is missing ? Can I dob it in ?
Tools / Options / View.
Examine the characters that Word uses to delimit paragraphs in the docx and the translated html.
I suspect that "paragraphs" in the translated html might be manual line breaks. If so, that would account for the fact that the paragraph count in the translated html is incorrect.

Convert word document to excel

I have a word document which needs to be converted to a table.
The catch however is, that the document contains a thousand pages and each page, needs to be an individual cell in the excel sheet. When I copy paste from Word, each line gets converted to one cell which i don't want. I need all the content between two page breaks to be a part of one cell.
To give some background on the issue, I need to basically create a csv from the the word file such that each page from the document is one value, hence I am trying to create a table.
Is there a way with which, this can be automated?
Found my solution here :
https://superuser.com/questions/747197/how-do-i-copy-word-tables-into-excel-without-splitting-cells-into-multiple-rows
It basically involved replacing 'pilcrow' characters into my file for line breaks and doing vice versa in excel.
One important thing though, the article says to type 'alt+0010' (the key combination for line break) something while replacing pilcrows in excel. However, that did not work for me. Ctrl+J does the trick though, it inserts line break character in excel replace box.
Cheers :)

How do I stop MS Word from auto-left-aligning new paragraphs generated from linked Excel objects?

I am created a form-letter using an Excel spreadsheet as a forming tool connected to a database and using paste-link to connect the results to an MS Word document.
Each section of the document is given a single cell to draw from which utilizes a formula to comprise itself of several other cells based on a logic determinate upon the data from the database queries.
All of this functions perfectly well.
The problem arises when the generated blocks of text from Excel include two carriage-returns in a row, creating what MS Word thinks is a new paragraph (and technically it is). The rest of the letter is justified, and I have attempted to set justified text as the default alignment. But no matter what I try, any newly formed paragraphs generated inside of linked text from Excel will be left-aligned.
For this form letter to function properly it must have justified text throughout. Inconsistent formatting won't be accepted by management.
To be clear, I have attempted to modify the settings of the "Normal" style of the document in Word, as well as creating a new style based on Normal called "Justified" and setting that as the default by selecting it and clicking "Change Styles" -> "Set as Default".
The first paragraph of any given block will always remain justified-aligned, it is only subsequent, newly-created (as far as MS Word knows) paragraphs that aren't. So I suspect I am just not setting the default properly or...I don't know, something.
I tried linking as unformatted text but that, for some maddening reason, includes QUOTATIONS MARKS bookending the text! I'm baffled and frustrated.
Please help. I don't like to look the fool at work.
While I still do not know how to make Word insert new paragraphs into linked blocks of text without left-aligning them, I have a working solution to my particular problem.
By forcing my spreadsheet to create blocks of text with the maximum number of paragraphs, then forcibly justifying the output in MS Word, I was able to ensure that, as long as I close the document between updates, that the text blocks will only shrink in size, rather than grow. This way, Word does not recognize the updated text as "new" paragraph, as there was already a paragraph in that block.
I saved the Word document with this overabundance of paragraphs, and put the Excel spreadsheet back the way it was.

Powerbuilder - Keep Column names when saving as Excel format

I am kind of new to PowerBuilder and I'd like to know if it was possible to keep the "visible" value of a column name when using the SaveAs() Method of my DataWindow. Currently, my report shows columns like "Numéro PB" or "Poste 1-3", but when I save, it shows the Database's names. ie: "no_pb" and "pos_1_3"...
As I am working on a deployed application, I have to make my changes and implementations As user-friendly as possible, and they won't understand anything of that.
I already use the dw2xls api to save an exact copy of the report, but they want to have an option saving only the raw data, and I don't think I can achieve it using their API.
Also, I was asked not to use the Excel OLE object to do it...
Anyone's got an idea?
Thanks,
Michael
dw.saveas(<string with filename and path>,CSV!,TRUE) saves the datawindow data as a comma separated value text file with the first row having the column headers (database names in the dw painter).
To set the column headings in a saveas you could first access the data with
any la_dwdata[] // declare array
la_dwdata = dw_1.Object.Data // get all data for all rows in dw_1 in the Primary! buffer
from here you would create an output file consisting initially of a series of strings along
with the column names you want and then the data from the array converted to a string (you loop through the array). If you insert commas between the values and name the file with the 'CSV' extension, it will load into Excel. Since this approach will also include any non visible data, you may have to use other logic to exclude them if the users don't want to see it.
So now you have a string consisting of lines of data separated by tabs along with a crlf at the end of each. You create your 'header string' with the user friendly column names in the format of 'blah,blah,blah~r~n' (this is three 'blah' strings separated by commas with a crlf at the end).
Now you parse the string obtained from dw_1.Object.Data to find the first line, strip it off, then replace it with the header string you created. You can use the replace method to replace the remaining tabs with a comma. Now you save the string to a file with a .CSV extension and you can load it into Excel
This assumes that your display columns match your raw columns. Create a DataStore ds_head . Set your report DW as the DataObject (no data). I'm calling the DataWindow with the report you want to save dw_report. You'll want to delete the two temporary files when you're done. You may need to specify EncodingUTF8! or some other encoding instead of ANSI depending on what the data in the DataWindow is. Note: Excel will open this CSV but some other programs may not like it because the header row has a trailing comma.
``
ds_head.saveAsFormattedText("file1.csv", EncodingANSI!, ",")
dw_report.saveAs("file2.csv", CSV!, FALSE, EncodingANSI!)
run("copy file1.csv file2.csv output.csv")

Inserting multiline text in a csv field

I want to insert a multiline text data in a CSV field.
Ex:
var data = "\nanything\nin\nthis\nfield";
var fields = "\"Datafield1\",\"Datafield2:"+data+"\"\n";
When I save fields into a csv file and open it using MS Excel, I get to see only the first column. But when I open the file using a text editor I see:
"Datafield1","Datafield2:
anything
in
this
field"
I don't know whether I am going against CSV standards. Even if I am going against Please help me with a workaround.
Thanks...
By default MS Excel uses semicolon as a separator. use ; and you'll see this:
Here I place some text followed by the NewLine char followed by some more text and the
whole string MUST be quoted into a field in a csv file.
Do not use a CR since EXCEL will place it in the next cell.
""2" + NL + "DATE""
When you invoke EXCEL, you will see this. You may have to auto size the height to see the entire cell.
2
DATE
Here's the code in Basic
CHR$(34,"2", 10,"DATE", 34)

Resources