Excel Print command, creating text template - templates

Hi I am new to VBA and was looking to output my Excel sheet data into a text template. So far all I have been able to do is output the data but I don't know where to go from there. What I have:
Private Sub CommandButton1_Click()
Dim myFile As String, rng As Range, cellValue As Variant, i As Integer, j As Integer
myFile = "C:\Users\Francis\Desktop\redirect.txt"
Set rng = Selection
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
Print #1, cellValue
Else
Print #1, cellValue,
End If
Next j
Next i
Close #1
End Sub
I wish to change this so the text output isn't just "celldataA*" "celldataB*" etc.
I want to make it so that the document starts with
<rule> and ends with </rule>
Then each row would come out as
<rule name="Rule rownumber*" patternSyntax="ExactMatch" stopProcessing="true">
<match url="celldataA*" />
<action type="Redirect" url="celldataB*" />
</rule>
Any pointers? It's that or I manually do it myself 3.5k times so any help at all is welcome.

These resources on generating XML from Excel should help you.
MS Office.Com: Create an XML data file and XML schema file from worksheet data
MSDN Library: Creating an XML Mapping Schema in Excel 2010
Mr Excel: Using XML in Excel 2003
essentially you create a schema file then output the xml data using that schema to define the data.

Related

XSL - How to make value into multiple lines within a cell of Excel?

I need to apply XSL to XML and generate report in Excel.
With following sample, becasue the source xml contains "&#xa", it creates newline. It ends up with writing 111 in row1 and 222 in row2 of Excel.
What I want to achieve is to "make the value into multiple lines WITHIN A CELL."
Could you please, help on this?
XML
<test value="111
222" />
XSL
<xsl:value-of select="./#value" />
Result
Excel Row 1 : 111
Excel Row 2 : 222
Resolved with following approach (edited)
<xsl:value-of select="concat('"', #value, '"')"/>

Increase xml:id with 1 find/replace with notepad++

a simple but short question. I am using notepad++ for my xml sheet. Heres is an example structure.
<category xml:id="S0078">
<catDesc>
<term>Test</term>
</catDesc>
</category>
<category xml:id="S0079">
<catDesc>
<term>Test</term>
</catDesc>
</category>
My question is how can i increase the id from S0078 to S300 by one with an simple search and replace command. I tried to use regular expression. but this was not working. Anyone have an idea ?
Use an XML aware tool to modify XML. For example, in xsh, you can do
open file.xml ;
for my $id in //category[
(#xml:id | preceding-sibling::category/#xml:id) = 'S0078'
][
(#xml:id | following-sibling::category/#xml:id) = 'S0300'
]/#xml:id
set $id/. { $id->value =~ s/([0-9]+)/$1+1/er } ;
save :b ;

XSLT 1.0 trying to convert node to lowercase to be compared with string

I have a param named $SearchRecipe which holds a string that i'm always passing a lowercase string to.
I have an XML file which i'm accessing using my xslt and example of some data from the xml file :
<ARecipe>
<RecipeNo>117</RecipeNo>
<ItemName>Veggie Sausages with Beans and Chips</ItemName>
<RecipeInfo>
<Ingredients>Linda Mcartney Sausages(2 per serving), Beans (400g per serving), Chips(Handful), Random Chillis (up to you how much)</Ingredients>
<Instructions>Put on fat fryer, insert chips and sausages. Put on wok, insert beans and add some random chillis etc. Heat beans and remove cooked Sausages and Chips. Place sausages and chips in tissue to remove excess oil. Place in a plate and serve warm.</Instructions>
<RecipeType>Main</RecipeType>
<Vegetarian>No</Vegetarian>
</RecipeInfo>
</ARecipe>
I'm running a query to go through all the ItemName nodes and compare it to my string which works fine. For example if I put V in the string it matches the ItemName in this (ARecipe) and this gets displayed in my xslt output. However if I pass v as a value then it won't bring this particular node (ARecipe).
I'm using these lines to go through the xml file :
<xsl:variable name="matchedRecipes"
select="ARecipe[
($SearchType = 'Start' and starts-with($Test, $SearchRecipe)) or
($SearchType = 'Contains' and contains(ItemName, $SearchRecipe)) or
($SearchType = 'RecipeType' and
contains(RecipeInfo/RecipeType, $SearchRecipe))
]" />
<xsl:if test="$SearchType = 'Start' or $SearchType = 'Contains'">
<xsl:apply-templates select="$matchedRecipes">
What I have tried so far is this :
<xsl:variable name="Test">
<xsl:value-of select="translate('ARecipe/ItemName',$ucletters,$lcletters)"/>
</xsl:variable>
I'm a novice in most languages etc, but I would be able to do this kind of thing in C# fairly easily, i'm having an absolute nightmate with xslt. Also when I wrote this request for help, I had already been doing this work for a few hours and the last hour I've spent trying all sorts to get this lowercase issue to resolve. So if I've not asked properly, I would like to appologize in advance.
If you would like to see the larger picture I have uploaded my code here :
http://pastebin.com/w8AsiQRg
You'll need to do something like this:
<xsl:variable name="SearchLc" select="translate($SearchRecipe, $ucletters, $lcletters)" />
<xsl:variable name="matchedRecipes"
select="ARecipe[
($SearchType = 'Start' and
starts-with(translate(ItemName, $ucletters, $lcletters), $SearchLc)) or
($SearchType = 'Contains' and
contains(translate(ItemName, $ucletters, $lcletters), $SearchLc)) or
($SearchType = 'RecipeType' and
contains(translate(RecipeInfo/RecipeType, $ucletters, $lcletters),
$SearchRecipe))
]" />
You can get the lowercase version of the search text ahead of time, but then you'll need to do the lower-casing of the individual items inside the selection XPath.

REGEX to link terms within displayed text

I have an application that I have inherited that dynamically builds HREF links within the displayed text. All seemed to be working well until we recently did a database change and our list of terms to link started to get returned from the query in a different order. This exposed a bug within the existing REGEX where it tries to place an HREF link within a preexisting HREF. Simply forcing a new ordering on the terms list is not an option. A term could be just one word, could be multiple words and even could be words formatted using HTML.
What would I need to adjust within the REGEX so that it ignores terms within the HREF attribute of an A element? Here is an example of what I am referring to:
<cfset Output = "This is some sample text to show the problem when we have term1 term2." />
<cfloop index="w" list="sample;term1 term2;term1" delimiters=";">
<cfset Output = "." & Variables.Output & "." />
<cfset Output = REReplaceNoCase(Variables.Output, "(?![</]#w#>)(\W)(#w#)(\W)", "\1\2\3", "one") />
<cfset Output = Mid(Variables.Output, 2, Len(Variables.Output)-2) />
</cfloop>
<cfoutput>#Variables.Output#</cfoutput>
Change the first (\W) in the regex to ([^=\w>]) and the second to ([^=\w<])
<cfset Output = REReplaceNoCase(Variables.Output, "(?![</]#w#>)([^=\w>])(#w#)([^=\w<])", "\1\2\3", "one") />

RegExpression to replace text within tags

I have HTML code as String variable in Coldfusion.
For example:
<cfset str = "<span class='xyz'> sample text within span </span>" >
Now I want to repalce the word span from text "sample text within span" but not the tag name.
Can someone help me?
Thanks in advance.
I'm going to dumbly answer your question:
<cfset str = "<span class='xyz'> sample text within span </span>" >
<cfdump var="#str#" />
<!--- Convert to list based on start and end tag brackets --->
<cfset arr = listToArray(str, ">,<") />
<!--- Replace the ACTUAL text --->
<cfset newStr = replace(str, arr[2], "my new text") />
<cfdump var="#newStr#" />
Disclaimer: if I caught myself writing this I would probably think myself on the wrong track.
This road leads to one trying to use regular expressions to parse HTML, regarded as a bad thing as mentioned in this article.
Perhaps you can explain your problem a little more and we can help.
I habe changed my code like this and it seems to work, but how efficent it is I don't know
Can someone please check it?
<cfset htmlcontents = ReReplaceNoCase(htmlcontents, "(>[^<]*?)(#Lcase(text2replace)#)", "\1<span class=suchehighlight>\2</span>","ALL")>
Thanks