SQL Server, parse a text which has multiple lines of html code into a table - sql

I have a skeleton of a code which I began to write for the following purpose:
use EAS
go
declare #entityID,int
declare #text,text
declare #col1,varchar --col1 is between <b>col1</b>
declare #col2,varchar --col2 are between >col2</td>
#entityID=entity_ID
#text = maAttributes_Text.value
#col1 = select SUBSTRING(#text,CHARINDEX('<b>',#text)+len('<b>'),
charindex('</b>',#text))
#col2 = select substring(#text, CHARINDEX('>',#text)+LEN('>'),charindex('</td>',#text))
begin
add to `table2` [entity_id], [caption], [value]
#entityID, #col1, #col2
end
I need to access a different table, table1, which contains fields entity_id, caption and value, as well as a few others which are unimportant.
entity_id | caption | value
----------|--------------|-------
12345 |Specifications| *html snippet*
What my code is supposed to do is, to find rows in table1 which have the value of 'Specifications' in field caption, then extract the entity_id value, store it, and then run a loop which takes all the rows of the html table and adds the info into another sql table.
For example, after running the code for one line of table1, table2 will look like as follows:
table2
entity_ID|Caption|Value
---------|-------|-----
12345 |length |10
12345 |width |10
12345 |height |10
et al.
Where all the information in table2 came from the html snippet which is stored in value field of table1.
My instincts tell me that I should use both a loop (I cannot make a loop in sql for the life of me) and the STRING_SPLIT function. However, I am not sure how to implement them.
After finishing the first row of table1, it will continue to the next row and the next row, as many rows WHERE caption in ('specifications')
EDIT: I understand my wording was pretty confusing. I will try to reexplain.
I have table1 which contains an ID number which is tied to an html snippet. The html snippet is the code for a table which contains many rows and two columns. My desired function will take the html snippet and parse it by row, and add it to table2 where the one ID number from table1 will be attached to the several rows of the html table. Therefore when the first few rows of the HTML SNIPPET are extracted, table2 will appear as so:
table2
entity_ID|Caption|Value
---------|-------|-----
12345 |length |10
12345 |width |10
12345 |height |10
wherein entity_ID is the unique ID number, and it is tied to several rows from within the HTML snippet. Caption is taken from col1 of the html snippet, and Value is taken from col2 of the html snippet.
EDIT 2:
A simple example of my situation:
table1
ID|Caption |Value
--|--------------|-----
1 |Specifications|*html snippet*
2 |Specifications|*html snippet2*
etc.
the code will take information from table1 and put it into `table2' as follows:
table2
ID|SpecName|Spec
--|--------|----
1 |Length |10
1 |Width |10
1 |Height |10
SpecName and Spec are fields from the html table that the html snippet created. Length, Width, Height are the information that the snippet is producing. 10, is the value for each of the SpecNames.
<table class="inline_sd_table"> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Accessories Optional</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Accommodates Ceiling Height</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>ADA Compliance</b></td> <td class="inline_sd_even_cell">See Additional Information above</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Blower Air Mover Type</b></td> <td class="inline_sd_odd_cell">Fan</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Blower Included</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Boost Mode</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>CFM (Airflow)</b></td> <td class="inline_sd_even_cell">190</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Color/Finish</b></td> <td class="inline_sd_odd_cell">Almond</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Control Feature Filter Reminder</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Damper Included</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Delay Shut Off</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Digital Clock</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Dishwasher Safe Filters</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Duct Connector Size</b></td> <td class="inline_sd_odd_cell">3-1/4" x 10", 7" Round Non-Ducted</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>ENERGY STARĀ® qualified</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Filter Included</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Filter Type</b></td> <td class="inline_sd_even_cell">Aluminum</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Flue Accommodates ceilings up to xx ft</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Heat Sentry - Temperature Sensor</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>HVI Certified</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Light Bulb Quantity</b></td> <td class="inline_sd_even_cell">1</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Light Bulbs Included</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Lighting Function</b></td> <td class="inline_sd_even_cell">One-level</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Lighting Type</b></td> <td class="inline_sd_odd_cell">Incandescent</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Max Sones/100 CFM</b></td> <td class="inline_sd_even_cell">4.1</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Minimum Height Above Cook Top</b></td> <td class="inline_sd_odd_cell">18"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Mounting Type</b></td> <td class="inline_sd_even_cell">Under Cabinet</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Nightlight</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Non-Stick Coated</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Product Depth (inches)</b></td> <td class="inline_sd_odd_cell">17-1/2"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Product Height (inches)</b></td> <td class="inline_sd_even_cell">6"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Product Width (inches)</b></td> <td class="inline_sd_odd_cell">42"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Rated Amps</b></td> <td class="inline_sd_even_cell">2.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Remote Control</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Horizontal Rectangular High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Horizontal Rectangular Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Vertical Rectangular High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Vertical Rectangular Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Vertical Round High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Vertical Round Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Switch Control Settings</b></td> <td class="inline_sd_even_cell">2</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Switch Style</b></td> <td class="inline_sd_odd_cell">Rocker</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Timer</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>UL Listed</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Voltage</b></td> <td class="inline_sd_even_cell">120</td> </tr> </table>

Your example is a little hard to follow, but does this help?
I modified a Parse/Split function to accept two non-like parameters. In this case '>' and '<'.
I should add, the TVF is very performant. The results are returned in 0.068 seconds.
Example
Declare #S varchar(max) = '<table class="inline_sd_table"> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Accessories Optional</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Accommodates Ceiling Height</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>ADA Compliance</b></td> <td class="inline_sd_even_cell">See Additional Information above</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Blower Air Mover Type</b></td> <td class="inline_sd_odd_cell">Fan</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Blower Included</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Boost Mode</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>CFM (Airflow)</b></td> <td class="inline_sd_even_cell">190</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Color/Finish</b></td> <td class="inline_sd_odd_cell">Almond</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Control Feature Filter Reminder</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Damper Included</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Delay Shut Off</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Digital Clock</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Dishwasher Safe Filters</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Duct Connector Size</b></td> <td class="inline_sd_odd_cell">3-1/4" x 10", 7" Round Non-Ducted</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>ENERGY STARĀ® qualified</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Filter Included</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Filter Type</b></td> <td class="inline_sd_even_cell">Aluminum</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Flue Accommodates ceilings up to xx ft</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Heat Sentry - Temperature Sensor</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>HVI Certified</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Light Bulb Quantity</b></td> <td class="inline_sd_even_cell">1</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Light Bulbs Included</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Lighting Function</b></td> <td class="inline_sd_even_cell">One-level</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Lighting Type</b></td> <td class="inline_sd_odd_cell">Incandescent</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Max Sones/100 CFM</b></td> <td class="inline_sd_even_cell">4.1</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Minimum Height Above Cook Top</b></td> <td class="inline_sd_odd_cell">18"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Mounting Type</b></td> <td class="inline_sd_even_cell">Under Cabinet</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Nightlight</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Non-Stick Coated</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Product Depth (inches)</b></td> <td class="inline_sd_odd_cell">17-1/2"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Product Height (inches)</b></td> <td class="inline_sd_even_cell">6"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Product Width (inches)</b></td> <td class="inline_sd_odd_cell">42"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Rated Amps</b></td> <td class="inline_sd_even_cell">2.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Remote Control</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Horizontal Rectangular High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Horizontal Rectangular Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Vertical Rectangular High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Vertical Rectangular Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Vertical Round High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Vertical Round Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Switch Control Settings</b></td> <td class="inline_sd_even_cell">2</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Switch Style</b></td> <td class="inline_sd_odd_cell">Rocker</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Timer</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>UL Listed</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Voltage</b></td> <td class="inline_sd_even_cell">120</td> </tr> </table> '
Select Item = max(case when RetCol=1 then RetVal end)
,Value = max(case when RetCol=0 then RetVal end)
From (
Select RetGrp=(Row_Number() over (Order By RetSeq)-1)/2
,RetCol=Row_Number() over (Order By RetSeq) % 2
,RetPos
,RetVal
From [dbo].[udf-Str-Extract](#S,'>','<')
Where RetVal>''
) A
Group By RetGrp
Order By RetGrp
Returns
The UDF if Interested
CREATE FUNCTION [dbo].[udf-Str-Extract] (#String varchar(max),#Delimiter1 varchar(100),#Delimiter2 varchar(100))
Returns Table
As
Return (
with cte1(N) As (Select 1 From (Values(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) N(N)),
cte2(N) As (Select Top (IsNull(DataLength(#String),0)) Row_Number() over (Order By (Select NULL)) From (Select N=1 From cte1 N1,cte1 N2,cte1 N3,cte1 N4,cte1 N5,cte1 N6) A ),
cte3(N) As (Select 1 Union All Select t.N+DataLength(#Delimiter1) From cte2 t Where Substring(#String,t.N,DataLength(#Delimiter1)) = #Delimiter1),
cte4(N,L) As (Select S.N,IsNull(NullIf(CharIndex(#Delimiter1,#String,s.N),0)-S.N,8000) From cte3 S)
Select RetSeq = Row_Number() over (Order By N)
,RetPos = N
,RetVal = left(RetVal,charindex(#Delimiter2,RetVal)-1)
From (
Select *,RetVal = Substring(#String, N, L)
From cte4
) A
Where charindex(#Delimiter2,RetVal)>1
)
/*
Max Length of String 1MM characters
Declare #String varchar(max) = 'Dear [[FirstName]] [[LastName]], ...'
Select * From [dbo].[udf-Str-Extract] (#String,'[[',']]')
*/
EDIT - Illustration of Raw Results
If you were to simply run
Select * from [dbo].[udf-Str-Extract](#S,'>','<')
The Results would be:

What about this? Note, I had to update the HTML blob because it had an unencoded &, so I just manually changed it to &. But as long as that's set up, this should work:
declare #x xml = cast('<table class="inline_sd_table"> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Accessories Optional</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Accommodates Ceiling Height</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>ADA Compliance</b></td> <td class="inline_sd_even_cell">See Additional Information above</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Blower Air Mover Type</b></td> <td class="inline_sd_odd_cell">Fan</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Blower Included</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Boost Mode</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>CFM (Airflow)</b></td> <td class="inline_sd_even_cell">190</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Color/Finish</b></td> <td class="inline_sd_odd_cell">Almond</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Control Feature Filter Reminder</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Damper Included</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Delay Shut Off</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Digital Clock</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Dishwasher Safe Filters</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Duct Connector Size</b></td> <td class="inline_sd_odd_cell">3-1/4" x 10", 7" Round Non-Ducted</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>ENERGY STAR&reg; qualified</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Filter Included</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Filter Type</b></td> <td class="inline_sd_even_cell">Aluminum</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Flue Accommodates ceilings up to xx ft</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Heat Sentry - Temperature Sensor</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>HVI Certified</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Light Bulb Quantity</b></td> <td class="inline_sd_even_cell">1</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Light Bulbs Included</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Lighting Function</b></td> <td class="inline_sd_even_cell">One-level</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Lighting Type</b></td> <td class="inline_sd_odd_cell">Incandescent</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Max Sones/100 CFM</b></td> <td class="inline_sd_even_cell">4.1</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Minimum Height Above Cook Top</b></td> <td class="inline_sd_odd_cell">18"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Mounting Type</b></td> <td class="inline_sd_even_cell">Under Cabinet</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Nightlight</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Non-Stick Coated</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Product Depth (inches)</b></td> <td class="inline_sd_odd_cell">17-1/2"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Product Height (inches)</b></td> <td class="inline_sd_even_cell">6"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Product Width (inches)</b></td> <td class="inline_sd_odd_cell">42"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Rated Amps</b></td> <td class="inline_sd_even_cell">2.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Remote Control</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Horizontal Rectangular High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Horizontal Rectangular Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Vertical Rectangular High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Vertical Rectangular Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Vertical Round High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Vertical Round Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Switch Control Settings</b></td> <td class="inline_sd_even_cell">2</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Switch Style</b></td> <td class="inline_sd_odd_cell">Rocker</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Timer</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>UL Listed</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Voltage</b></td> <td class="inline_sd_even_cell">120</td> </tr> </table> ' as xml)
select
Name = t.c.value('(td/b)[1]', 'varchar(250)'),
Value = t.c.value('(td)[2]', 'varchar(250)')
from #x.nodes('/table/tr') as t(c)

Example of Using a TVF within a CROSS APPLY
Insert Into Table2
Select ID = A.Entity_ID
,B.*
From Table1 A
Cross Apply (
Select Top 10000
SpecName = max(case when RetCol=1 then RetVal end)
,Spec = max(case when RetCol=0 then RetVal end)
From (
Select RetGrp=(Row_Number() over (Order By RetSeq)-1)/2
,RetCol=Row_Number() over (Order By RetSeq) % 2
,RetPos
,RetVal
From [dbo].[udf-Str-Extract](A.value,'>','<')
Where RetVal>''
) B1
Group By RetGrp
Order By RetGrp
) B
Select * from Table2

Related

How do I render numbers like 4999 to $4,999.00 in datatables?

If the data source is from an existed DOM, rather than some JSON variable. How do I convert the numbers like 4999 to $4,999.00 in datatables?
I don't know what kind of options should be passed to the main function.
$('#example').DataTable(
{
// need help on this
}
);
Here is the code:
$(document).ready(function() {
//Only needed for the filename of export files.
//Normally set in the title tag of your page.
document.title='Simple DataTable';
// DataTable initialisation
$('#example').DataTable(
{
}
);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<a class="btn btn-success" style="float:left;margin-right:20px;" href="https://codepenio/collection/XKgNLN/" target="_blank">Other examples on Codepen</a>
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Order</th>
<th>Description</th>
<th>Deadline</th>
<th>Status</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Alphabet puzzle</td>
<td>2016/01/15</td>
<td>Done</td>
<td data-order="1000">1000</td>
</tr>
<tr>
<td>2</td>
<td>Layout for poster</td>
<td>2016/01/31</td>
<td>Planned</td>
<td data-order="1834">1834</td>
</tr>
<tr>
<td>3</td>
<td>Image creation</td>
<td>2016/01/23</td>
<td>To Do</td>
<td data-order="1500">1500</td>
</tr>
<tr>
<td>4</td>
<td>Create font</td>
<td>2016/02/26</td>
<td>Done</td>
<td data-order="1200">1200</td>
</tr>
<tr>
<td>5</td>
<td>Sticker production</td>
<td>2016/02/18</td>
<td>Planned</td>
<td data-order="2100">2100</td>
</tr>
<tr>
<td>6</td>
<td>Glossy poster</td>
<td>2016/03/17</td>
<td>To Do</td>
<td data-order="899">899</td>
</tr>
<tr>
<td>7</td>
<td>Beer label</td>
<td>2016/05/28</td>
<td>Confirmed</td>
<td data-order="2499">2499</td>
</tr>
<tr>
<td>8</td>
<td>Shop sign</td>
<td>2016/04/19</td>
<td>Offer</td>
<td data-order="1099">1099</td>
</tr>
<tr>
<td>9</td>
<td>X-Mas decoration</td>
<td>2016/10/31</td>
<td>Confirmed</td>
<td data-order="1750">1750</td>
</tr>
<tr>
<td>10</td>
<td>Halloween invite</td>
<td>2016/09/12</td>
<td>Planned</td>
<td data-order="400">400</td>
</tr>
<tr>
<td>11</td>
<td>Wedding announcement</td>
<td>2016/07/09</td>
<td>To Do</td>
<td data-order="299">299</td>
</tr>
<tr>
<td>12</td>
<td>Member pasport</td>
<td>2016/06/22</td>
<td>Offer</td>
<td data-order="149">149</td>
</tr>
<tr>
<td>13</td>
<td>Drink tickets</td>
<td>2016/11/01</td>
<td>Confirmed</td>
<td data-order="199">199</td>
</tr>
<tr>
<td>14</td>
<td>Album cover</td>
<td>2017/03/15</td>
<td>To Do</td>
<td data-order="4999">4999</td>
</tr>
<tr>
<td>15</td>
<td>Shipment box</td>
<td>2017/02/08</td>
<td>Offer</td>
<td data-order="1399">1399</td>
</tr>
<tr>
<td>16</td>
<td>Wooden puzzle</td>
<td>2017/01/11</td>
<td>Done</td>
<td data-order="1000">1000</td>
</tr>
<tr>
<td>17</td>
<td>Fashion Layout</td>
<td>2016/01/30</td>
<td>Planned</td>
<td data-order="1834">1834</td>
</tr>
<tr>
<td>18</td>
<td>Toy creation</td>
<td>2016/01/10</td>
<td>To Do</td>
<td data-order="1550">1550</td>
</tr>
<tr>
<td>19</td>
<td>Create stamps</td>
<td>2016/02/26</td>
<td>Done</td>
<td data-order="1220">1220</td>
</tr>
<tr>
<td>20</td>
<td>Sticker design</td>
<td>2017/02/18</td>
<td>Planned</td>
<td data-order="2100">2100</td>
</tr>
<tr>
<td>21</td>
<td>Poster rock concert</td>
<td>2017/04/17</td>
<td>To Do</td>
<td data-order="899">899</td>
</tr>
<tr>
<td>22</td>
<td>Wine label</td>
<td>2017/05/28</td>
<td>Confirmed</td>
<td data-order="2799">2799</td>
</tr>
<tr>
<td>23</td>
<td>Shopping bag</td>
<td>2017/04/19</td>
<td>Offer</td>
<td data-order="1299">1299</td>
</tr>
<tr>
<td>24</td>
<td>Decoration for Easter</td>
<td>2017/10/31</td>
<td>Confirmed</td>
<td data-order="1650">1650</td>
</tr>
<tr>
<td>25</td>
<td>Saint Nicolas colorbook</td>
<td>2017/09/12</td>
<td>Planned</td>
<td data-order="510">510</td>
</tr>
<tr>
<td>26</td>
<td>Wedding invites</td>
<td>2017/07/09</td>
<td>To Do</td>
<td data-order="399">399</td>
</tr>
<tr>
<td>27</td>
<td>Member pasport</td>
<td>2017/06/22</td>
<td>Offer</td>
<td data-order="249">249</td>
</tr>
<tr>
<td>28</td>
<td>Drink tickets</td>
<td>2017/11/01</td>
<td>Confirmed</td>
<td data-order="199">199</td>
</tr>
<tr>
<td>29</td>
<td>Blue-Ray cover</td>
<td>2018/03/15</td>
<td>To Do</td>
<td data-order="1999">1999</td>
</tr>
<tr>
<td>30</td>
<td>TV carton</td>
<td>2019/02/08</td>
<td>Offer</td>
<td data-order="1369">1369</td>
</tr>
</tbody>
</table>
You can use the createdCell() callback, inside DataTables' columnDefs initializazion option.
Inside the callback, you have access to the <td> element of the created cell and to its data, so you can manipulate both in the way that you prefer.
In this fiddle I changed the shown data format using the Intl.NumberFormat() api:
$(document).ready(function() {
// Only needed for the filename of export files.
// Normally set in the title tag of your page.
document.title = 'Simple DataTable';
// DataTable initialisation
$('#example').DataTable({
columnDefs: [{
targets: 4, // <-- this is the target column
createdCell: function(cell, cellData, rowData, rowIndex, colIndex) {
const formattedContent = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD'
}).format(cellData);
cell.innerHTML = formattedContent;
},
}]
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" rel="stylesheet" />
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<a class="btn btn-success" style="float:left;margin-right:20px;" href="https://codepenio/collection/XKgNLN/" target="_blank">Other examples on Codepen</a>
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Order</th>
<th>Description</th>
<th>Deadline</th>
<th>Status</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Alphabet puzzle</td>
<td>2016/01/15</td>
<td>Done</td>
<td data-order="1000">1000</td>
</tr>
<tr>
<td>2</td>
<td>Layout for poster</td>
<td>2016/01/31</td>
<td>Planned</td>
<td data-order="1834">1834</td>
</tr>
<tr>
<td>3</td>
<td>Image creation</td>
<td>2016/01/23</td>
<td>To Do</td>
<td data-order="1500">1500</td>
</tr>
<tr>
<td>4</td>
<td>Create font</td>
<td>2016/02/26</td>
<td>Done</td>
<td data-order="1200">1200</td>
</tr>
<tr>
<td>5</td>
<td>Sticker production</td>
<td>2016/02/18</td>
<td>Planned</td>
<td data-order="2100">2100</td>
</tr>
<tr>
<td>6</td>
<td>Glossy poster</td>
<td>2016/03/17</td>
<td>To Do</td>
<td data-order="899">899</td>
</tr>
<tr>
<td>7</td>
<td>Beer label</td>
<td>2016/05/28</td>
<td>Confirmed</td>
<td data-order="2499">2499</td>
</tr>
<tr>
<td>8</td>
<td>Shop sign</td>
<td>2016/04/19</td>
<td>Offer</td>
<td data-order="1099">1099</td>
</tr>
<tr>
<td>9</td>
<td>X-Mas decoration</td>
<td>2016/10/31</td>
<td>Confirmed</td>
<td data-order="1750">1750</td>
</tr>
<tr>
<td>10</td>
<td>Halloween invite</td>
<td>2016/09/12</td>
<td>Planned</td>
<td data-order="400">400</td>
</tr>
<tr>
<td>11</td>
<td>Wedding announcement</td>
<td>2016/07/09</td>
<td>To Do</td>
<td data-order="299">299</td>
</tr>
<tr>
<td>12</td>
<td>Member pasport</td>
<td>2016/06/22</td>
<td>Offer</td>
<td data-order="149">149</td>
</tr>
<tr>
<td>13</td>
<td>Drink tickets</td>
<td>2016/11/01</td>
<td>Confirmed</td>
<td data-order="199">199</td>
</tr>
<tr>
<td>14</td>
<td>Album cover</td>
<td>2017/03/15</td>
<td>To Do</td>
<td data-order="4999">4999</td>
</tr>
<tr>
<td>15</td>
<td>Shipment box</td>
<td>2017/02/08</td>
<td>Offer</td>
<td data-order="1399">1399</td>
</tr>
<tr>
<td>16</td>
<td>Wooden puzzle</td>
<td>2017/01/11</td>
<td>Done</td>
<td data-order="1000">1000</td>
</tr>
<tr>
<td>17</td>
<td>Fashion Layout</td>
<td>2016/01/30</td>
<td>Planned</td>
<td data-order="1834">1834</td>
</tr>
<tr>
<td>18</td>
<td>Toy creation</td>
<td>2016/01/10</td>
<td>To Do</td>
<td data-order="1550">1550</td>
</tr>
<tr>
<td>19</td>
<td>Create stamps</td>
<td>2016/02/26</td>
<td>Done</td>
<td data-order="1220">1220</td>
</tr>
<tr>
<td>20</td>
<td>Sticker design</td>
<td>2017/02/18</td>
<td>Planned</td>
<td data-order="2100">2100</td>
</tr>
<tr>
<td>21</td>
<td>Poster rock concert</td>
<td>2017/04/17</td>
<td>To Do</td>
<td data-order="899">899</td>
</tr>
<tr>
<td>22</td>
<td>Wine label</td>
<td>2017/05/28</td>
<td>Confirmed</td>
<td data-order="2799">2799</td>
</tr>
<tr>
<td>23</td>
<td>Shopping bag</td>
<td>2017/04/19</td>
<td>Offer</td>
<td data-order="1299">1299</td>
</tr>
<tr>
<td>24</td>
<td>Decoration for Easter</td>
<td>2017/10/31</td>
<td>Confirmed</td>
<td data-order="1650">1650</td>
</tr>
<tr>
<td>25</td>
<td>Saint Nicolas colorbook</td>
<td>2017/09/12</td>
<td>Planned</td>
<td data-order="510">510</td>
</tr>
<tr>
<td>26</td>
<td>Wedding invites</td>
<td>2017/07/09</td>
<td>To Do</td>
<td data-order="399">399</td>
</tr>
<tr>
<td>27</td>
<td>Member pasport</td>
<td>2017/06/22</td>
<td>Offer</td>
<td data-order="249">249</td>
</tr>
<tr>
<td>28</td>
<td>Drink tickets</td>
<td>2017/11/01</td>
<td>Confirmed</td>
<td data-order="199">199</td>
</tr>
<tr>
<td>29</td>
<td>Blue-Ray cover</td>
<td>2018/03/15</td>
<td>To Do</td>
<td data-order="1999">1999</td>
</tr>
<tr>
<td>30</td>
<td>TV carton</td>
<td>2019/02/08</td>
<td>Offer</td>
<td data-order="1369">1369</td>
</tr>
</tbody>
</table>

Replicating a table

I'm having trouble replicating this table. I'm confused with the rowspan and colspan. I would really appreciate it if someone helps.
Click here to view image of the table
Here you go:
<table>
<tr>
<td colspan="7">The Error Rate on Different Forms</td>
</tr>
<tr>
<td rowspan="2">Form name</td>
<td rowspan="2">A</td>
<td rowspan="2">B</td>
<td rowspan="2">Total Fields (X = A x B)</td>
<td rowspan="2">Fields with errors (Y)</td>
<td colspan="2">Error rate* (Y/X) x 100 (%)</td>
</tr>
<tr>
<td>X/Y</td>
<td>%age</td>
</tr>
<tr>
<td colspan="7">High Risk Errors</td>
</tr>
<!-- normal tr td -->
<tr>
<td colspan="7">Low Risk Error</td>
</tr>
<!-- normal tr td -->
</table>

How to scale content so it fits in a pagesize in itextpdf?

I have to take some reports in html to pdf using itextpdf. Mi client has printers using 4x11 inches therefore the reports must have this size.
The problem is he wants that reports that usually takes a page and a half in 4x11 fits in one single page of 4x11. As if we were scaling an image.
Following an itext7 tutorial about how to use pdfHtml to create single page content I created the reports in an 4xcontent height page size.
The question itself is if there is anyway to scale the content so it fits in the 4x11 inches regardless of the content height
Here is an example of the html code to convert into pdf
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator"
content="HTML Tidy for Java (vers. 2009-12-01), see jtidy.sourceforge.net"/>
<title>#Title</title>
<style type="text/css">
html, body {
padding: 0;
margin: 0;
}
#media print {
#page {
margin: 2px;
}
}
body {
font-family: Verdana, sans-serif;
font-size: 10px;
}
</style>
</head>
<body>
<div class="divTicketWrapper">
<div class="headerLogo"></div>
<div class="headerInfo">
<div style="font-size:18px; font-weight:NUMBERd;">COMPANY, LLC</div>
<div>COMPANY NAME</div>
<div>US, 123344</div>
<div>EMERGENCY CONTACT: 12345667</div>
</div>
<!-- LOAD INFORMATION -->
<div class="sectionHeader" width="100%">
<h3 style="font-size:10px;">INFORMATION</h3>
</div>
<table width="100%">
<tr width="100%">
<td class="divLabel">Product Type:</td>
<td class="divField" colspan="3">product 1</td>
</tr>
<tr width="100%">
<td class="divLeftColumn divLabel">NUMBER #:</td>
<td class="divLeftColumn divField">1234556</td>
<td class="divRightColumn divLabel">Trucked By:</td>
<td class="divRightColumn divField">COMPANY, LLC</td>
</tr>
<tr width="100%">
<td class="divLeftColumn divLabel">Ticket #:</td>
<td class="divLeftColumn divField">123243355</td>
<td class="divRightColumn divLabel">Accepted Date/Time:</td>
<td class="divRightColumn divField">04/28/2000 22:07</td>
</tr>
<tr width="100%">
<td class="divLeftColumn divLabel">Split Ticket # w/ #:</td>
<td class="divLeftColumn divField"></td>
<td class="divRightColumn divLabel">Confirmation #:</td>
<td class="divRightColumn divField">1233223423</td>
</tr>
<!-- DROP OFF TICKET NUMBER -->
<tr width="100%">
<td class="divLeftColumn divLabel">Receipt #:</td>
<td class="divLeftColumn divField"></td>
<td class="divRightColumn divLabel">DO Receipt #:</td>
<td class="divRightColumn divField"></td>
</tr>
</table>
<div class="sectionHeader" width="100%">
<h3 style="font-size:10px;">INFORMATION</h3>
</div>
<table width="100%">
<tr width="100%">
<td class="divLabel">INFORMATION:</td>
<td class="divField" colspan="3">COMPANY LLC</td>
</tr>
<tr width="100%">
<td class="divLabel">Name:</td>
<td class="divField" colspan="3">COMPANY A 2,3,4</td>
</tr>
<tr width="100%">
<td class="divLabel">Other name:</td>
<td class="divField" colspan="3">COMPANY</td>
</tr>
<tr width="100%">
<td class="divLeftColumn divLabel">SOMETHING #:</td>
<td class="divLeftColumn divField">COMPANY</td>
<td class="divRightColumn divLabel">Arrival Date & Time::</td>
<td class="divRightColumn divField">04/28/2000 22:39</td>
</tr>
<tr width="100%">
<td class="divLeftColumn divLabel">SOMETHING #:</td>
<td class="divLeftColumn divField"></td>
<td class="divRightColumn divLabel">Load Time:</td>
<td class="divRightColumn divField">00:08</td>
</tr>
<tr width="100%">
<td class="divLeftColumn divLabel">Legal Description:</td>
<td class="divLeftColumn divField"></td>
<td class="divRightColumn divLabel">Wait Time:</td>
<td class="divRightColumn divField">00:00</td>
</tr>
<tr width="100%">
<td class="divLeftColumn divLabel">Latitude:</td>
<td class="divLeftColumn divField">1212324343</td>
<td class="divRightColumn divLabel">SOMETHING Date & Time:</td>
<td class="divRightColumn divField">04/28/2000 22:47</td>
</tr>
<tr width="100%">
<td class="divLeftColumn divLabel">Longitude:</td>
<td class="divLeftColumn divField">123322344</td>
<td class="divRightColumn divLabel">Loaded Miles:</td>
<td class="divRightColumn divField">100</td>
</tr>
<tr width="100%">
<td class="divLabel">County, State::</td>
<td class="divField" colspan="3">COMPANY</td>
</tr>
<tr width="100%">
<td class="divLabel">Wait Time Notes:</td>
<td class="divField" colspan="3"></td>
</tr>
<tr width="100%">
<td class="divLabel">Reject Notes:</td>
<td class="divField" colspan="3"></td>
</tr>
<tr width="100%">
<td class="divLabel">Other Notes:</td>
<td class="divField" colspan="3">SOMETHING In Production;</td>
</tr>
</table>
<div class="sectionHeader" width="100%">
<h3 style="font-size:10px;">PICK UP</h3>
</div>
<table width="100%">
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">ACCEPT</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap"></td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY Type</td>
<td class="divLeftColumn divField divFieldWrap">COMPANY</td>
<td class="divRightColumn divLabel">BS&W(%)</td>
<td class="divRightColumn divField divFieldWrap">0.1</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">COMPANY</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">90.0</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">0.0</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">90.0</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">0.01</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">90.0</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">0 ft 0 in 0
in<br/>
<br/>
(0.0 in)
</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">53.0</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">0 ft 0 in 0
in<br/>
<br/>
(0.0 in)
</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">49.9</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">194.0</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">COMPANY</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">190.53</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">04/28/2000
22:39
</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">190.72</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">121313</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">0 ft 0 in 0
in<br/>
<br/>
(0.0 in)
</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">04/28/2000
22:47
</td>
</tr>
</table>
<!-- / SOMETHING INFORMATION -->
<div class="sectionHeader" width="100%">
<h3 style="font-size:10px;">PICK UP</h3>
</div>
<table width="100%">
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">ACCEPT</td>
<td class="divRightColumn divLabel">Reject Reason</td>
<td class="divRightColumn divField divFieldWrap"></td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">COMPANY</td>
<td class="divRightColumn divLabel">BS&W(%)</td>
<td class="divRightColumn divField divFieldWrap">0.1</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">COMPANY</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">90.0</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">0.0</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">90.0</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">0.01</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">90.0</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">0 ft 0 in 0
in<br/>
<br/>
(0.0 in)
</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">53.0</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">0 ft 0 in 0
in<br/>
<br/>
(0.0 in)
</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">49.9</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">194.0</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">COMPANY</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">190.53</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">04/28/2000
22:39
</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">190.72</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">108712121215</td>
</tr>
<tr>
<td class="divLeftColumn divLabel">COMPANY</td>
<td class="divLeftColumn divField divFieldWrap">0 ft 0 in 0
in<br/>
<br/>
(0.0 in)
</td>
<td class="divRightColumn divLabel">COMPANY</td>
<td class="divRightColumn divField divFieldWrap">04/28/2000
22:47
</td>
</tr>
</table>
<!-- SOMETHING INFORMATION -->
<div class="sectionHeader" width="100%">
<h3 style="font-size:10px;">COMPANY</h3>
</div>
<table width="100%">
<tr width="100%">
<td class="divLabel">COMPANY:</td>
<td class="divField" colspan="3"></td>
</tr>
<tr width="100%">
<td class="divLabel">COMPANY:</td>
<td class="divField" colspan="3"></td>
</tr>
<tr width="100%">
<td class="divLeftColumn divLabel">COMPANY:</td>
<td class="divLeftColumn divField"></td>
<td class="divRightColumn divLabel">Arrival Date & Time:</td>
<td class="divRightColumn divField"></td>
</tr>
<tr width="100%">
<td class="divLeftColumn divLabel">COMPANY #:</td>
<td class="divLeftColumn divField"></td>
<td class="divRightColumn divLabel">COMPANY:</td>
<td class="divRightColumn divField"></td>
</tr>
<tr width="100%">
<td class="divLeftColumn divLabel">Latitude:</td>
<td class="divLeftColumn divField"></td>
<td class="divRightColumn divLabel">Wait Time:</td>
<td class="divRightColumn divField"></td>
</tr>
<tr width="100%">
<td class="divLeftColumn divLabel">Longitude:</td>
<td class="divLeftColumn divField"></td>
<td class="divRightColumn divLabel">SOMETHING Date & Time:</td>
<td class="divRightColumn divField"></td>
</tr>
<tr width="100%">
<td class="divLabel">COMPANY</td>
<td class="divField" colspan="3">COMPANY</td>
</tr>
<tr width="100%">
<td class="divLabel">Wait Time Notes:</td>
<td class="divField" colspan="3"></td>
</tr>
<tr width="100%">
<td class="divLabel">Other Notes:</td>
<td class="divField" colspan="3"></td>
</tr>
</table>
<!-- / SOMETHING INFORMATION -->
<!-- SOMETHING SOMETHING & SOMETHING -->
<div class="">
<table width="100%" style="border-collapse: collapse;">
<tr width="100%">
<td class="divLeftColumn divLabel divLabelBackGround">
COMPANY
</td>
<td class="divRightColumn divLabel divLabelBackGround">
COMPANY
</td>
</tr>
</table>
<table width="100%">
<tr width="100%">
<td class="divLeftColumn divLabel">COMPANY #:</td>
<td class="divLeftColumn divField">100</td>
<td class="divRightColumn divLabel">COMPANY #:</td>
<td class="divRightColumn divField"></td>
</tr>
<tr width="100%">
<td class="divLeftColumn divLabel">COMPANY #:</td>
<td class="divLeftColumn divField">1015</td>
<td class="divRightColumn divLabel">COMPANY #:</td>
<td class="divRightColumn divField"></td>
</tr>
<tr width="100%">
<td class="divLeftColumn divLabel">COMPANY:</td>
<td class="divLeftColumn divField">COMPANY</td>
<td class="divRightColumn divLabel">COMPANY:</td>
<td class="divRightColumn divField"></td>
</tr>
<tr width="100%">
<td class="divLeftColumn divLabel">COMPANY:</td>
<td class="divLeftColumn divField">102</td>
<td class="divRightColumn divLabel">COMPANY:</td>
<td class="divRightColumn divField"></td>
</tr>
</table>
</div>
<p>hola</p>
<table width="100%" style="border-collapse: collapse;">
<tr width="100%">
<td style="text-align:center;"></td>
</tr>
</table>
</div>
</body>
</html>
Now using this java code I get the PDF report in twoo 4x11 inches pages
String path = "src/main/resources/html/";
String pdFName = String.valueOf(UUID.randomUUID());
PdfWriter pdfWriter = new PdfWriter(new FileOutputStream(path + pdFName + ".pdf"));
PdfDocument pdf = new PdfDocument(pdfWriter);
pdf.setDefaultPageSize(new PageSize(new Rectangle(288, 792)));//4x11 inches
Document document = HtmlConverter.convertToDocument(new FileInputStream(path + "out.html"), pdf, null);
document.close();
And using this java code I get the hole report in one single Pdf 4x15 inches page
ConverterProperties properties = new ConverterProperties();
PdfWriter pdfWriter = new PdfWriter(new FileOutputStream(path + pdFName + ".pdf"));
PdfDocument pdf = new PdfDocument(pdfWriter);
pdf.setDefaultPageSize(new PageSize(new Rectangle(288, 14400)));//4x full PDF height
Document document = HtmlConverter.convertToDocument(new FileInputStream(path + "out.html"), pdf, properties);
EndPosition endPosition = new EndPosition();
LineSeparator separator = new LineSeparator(endPosition);
document.add(separator);
document.getRenderer().close();
PdfPage page = pdf.getPage(1);
float y = endPosition.getY() - 36;
page.setMediaBox(new Rectangle(0, y, 288, 14400 - y));
document.close();
private static class EndPosition implements ILineDrawer {
protected float y;
public float getY() {
return y;
}
#Override
public void draw(PdfCanvas pdfCanvas, Rectangle rectangle) {
this.y = rectangle.getY();
}
#Override
public float getLineWidth() {
return 0;
}
#Override
public void setLineWidth(float v) {
}
#Override
public Color getColor() {
return null;
}
#Override
public void setColor(Color color) {
}
}
But I still need the hole page to fit 4x11 inches regardles of the height of the content. When I print the 4x15 inches page I can specify the printer to fit the content into 4x11 inches and the printer shrinks it... but I need to this using code not the printer.
Of course simply resizing 4x15 page into 4x11 one is possible with transformation matrix in the content stream of a page, but that will skew all the content, which is likely undesirable.
Instead, what we can do is first convert the HTML into elements instead of converting to the document directly and then scale the font size with various scale factors and emulate layouting elements on the page to see at which scale factor all the elements will fit into one page completely.
Please note that the approach and code I am describing relies on some assumptions made about input data, e.g. that the HTML does not use advanced CSS layouts like floats or absolute positioning as well as that it does not contain images. For more complex inputs some additional modifications or complete rewrite of the code might be required, so please test it carefully and use it at your own risk.
To test out different font sizes, binary search is our best friend and allows a giant speed up.
First off, a helper function to scale font size of the element recursively:
private void scaleFontSizeRecursively(IElement element, float scale) {
if (element.hasOwnProperty(Property.FONT_SIZE)) {
UnitValue fontSize = element.getOwnProperty(Property.FONT_SIZE);
fontSize.setValue(fontSize.getValue() * scale);
}
if (element instanceof com.itextpdf.layout.element.AbstractElement) {
for (Object child : ((AbstractElement) element).getChildren()) {
scaleFontSizeRecursively((IElement) child, scale);
}
}
}
Now the meaty part of the code. In the binary search body we scale all the font sizes of the elements and emulate complete document layout to see if one page was enough. Then we do some clean ups and try again until we converge. You can tweak the number of iterations (set at 20 in the code) to your own taste for the accuracy/speed trade-off. You can also tweak left and right bounds of the binary search if you can make such judgment depending on the expected input. Finally, we set the font size scale we converged at and do the final layout.
PdfDocument pdf = new PdfDocument(pdfWriter);
pdf.setDefaultPageSize(new PageSize(new Rectangle(72 * 4, 72 * 11)));
// Important to set last boolean parameter to false so that added elements are not drawn immediately
Document document = new Document(pdf, pdf.getDefaultPageSize(), false);
List<IElement> elements = HtmlConverter.convertToElements(html);
float lFontSizeScale = 0.001f;
float rFontSize = 1;
// Initially adding all the elements into the document. They will be document's children from now on
for (IElement element : elements) {
if (element instanceof IBlockElement) {
document.add((IBlockElement) element);
} else {
throw new IllegalStateException("Unexpected situation that needs to be additionally handled in code");
}
}
for (int i = 0; i < 20; i++) {
float midFontSize = (lFontSizeScale + rFontSize) / 2;
for (IElement element : elements) {
scaleFontSizeRecursively(element, midFontSize);
}
// Relayouting all the elements with the new font size
document.relayout();
// See if one page was enough
if (document.getPdfDocument().getNumberOfPages() == 1) {
lFontSizeScale = midFontSize;
} else {
rFontSize = midFontSize;
}
// Roll back our font size scaling
for (IElement element : elements) {
scaleFontSizeRecursively(element, 1 / midFontSize);
}
// Remove extra created pages
while (pdf.getNumberOfPages() > 1) {
pdf.removePage(2);
}
}
// Finally setting the font scale that was the match for us and layouting again
for (IElement element : elements) {
scaleFontSizeRecursively(element, lFontSizeScale);
}
document.relayout();
System.out.println("Resultant scale: " + lFontSizeScale);
document.close();
Running the code produces a valid document with one page of 4x11 inches and all the content is present there. Console output:
Resultant scale: 0.6297823
As you can see, we needed to scale down at ~63%

Finding Duplicate Pairs in Excel

So I have this summary sheet. It contains data from multiple workbooks going across.
It's not like this question, because what I'm trying to do is find all the inconsistant pairs of data in this worksheet going across and highlight them.
Here is a fiddle that explains what I want to accomplish. I have a large worksheet, and would like to compare the first 2 rows with the next 2 rows etc. throughout the worksheet. Below is an HTML representation of what I am trying to accomplish.
<table class="tg">
<tr>
<th class="tg-031e">#INT1</th>
<th class="tg-031e">#INT1</th>
<th class="tg-031e">#INT2</th>
<th class="tg-031e">#INT2</th>
<th class="tg-031e">#INT3</th>
<th class="tg-031e">#INT3</th>
</tr>
<tr>
<td class="tg-031e">Apples</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Bananas</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Apples</td>
<td class="tg-031e">Y</td>
</tr>
<tr>
<td class="tg-031e">Bananas</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Peppers</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Bananas</td>
<td class="tg-031e">Y</td>
</tr>
<tr>
<td class="tg-031e">Peppers</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Pomegranite</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Peppers</td>
<td class="tg-031e">Y</td>
</tr>
<tr>
<td class="tg-031e">Pomegranite</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Nuts</td>
<td class="tg-031e">YYYYYNN</td>
<td class="tg-031e">Pomegranite</td>
<td class="tg-031e">Y</td>
</tr>
<tr>
<td class="tg-031e">Nuts</td>
<td class="tg-031e">YYYYYYNN</td>
<td class="tg-031e">Smango</td>
<td class="tg-031e">NNNYYNNN</td>
<td class="tg-031e">Nuts</td>
<td class="tg-031e">NNNYNNNN</td>
</tr>
<tr>
<td class="tg-zl7m">Oranges</td>
<td class="tg-zl7m">YYYYNNNN</td> <!-- this oranges is different from... -->
<td class="tg-031e">Blackberries</td>
<td class="tg-031e">NNNYYNNNN</td>
<td class="tg-zl7m">Oranges</td>
<td class="tg-zl7m">NNNYYNNN</td> <!-- ...this one -->
</tr>
<tr>
<td class="tg-031e">Smango</td>
<td class="tg-031e">NNNYYNNN</td>
<td class="tg-031e">Berries</td>
<td class="tg-031e">YYNYNNNN</td>
<td class="tg-031e">Smango</td>
<td class="tg-031e">Y</td>
</tr>
<tr>
<td class="tg-031e">Skiwi</td>
<td class="tg-031e">NNNYNNNN</td>
<td class="tg-031e">Beer</td>
<td class="tg-031e">NNNYNNNN</td>
<td class="tg-031e">Steaks</td>
<td class="tg-031e">Y</td>
</tr>
<tr>
<td class="tg-031e">Steaks</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Blueberries</td>
<td class="tg-031e">YNNYNNNN</td>
<td class="tg-031e">Steaksauce</td>
<td class="tg-031e">NNNYNNNN</td>
</tr>
<tr>
<td class="tg-zl7m">Steaksauce</td>
<td class="tg-zl7m">YYNYNNNN</td>
<td class="tg-031e">Blucheese</td>
<td class="tg-031e">NNNYNNNN</td>
<td class="tg-zl7m">Apricot</td>
<td class="tg-zl7m">YYYYNNNN</td>
</tr>
<tr>
<td class="tg-031e">Apricot</td>
<td class="tg-031e">YYYYNNNN</td>
<td class="tg-031e">Blackberries</td>
<td class="tg-031e">NNNYNNNN</td>
<td class="tg-031e">Milkshake</td>
<td class="tg-031e">NNNYNNNN</td>
</tr>
</table>
I have tried VBA solutions and also conditional formatting. Any solution that will make this work is greatly appreciated.
Thank you.
I think this array formula should work:-
=SUM(ISODD(COLUMN())*($A$2:$E$12=A2)*($B$2:$F$12<>B2))
if the table starts in A1, this can be applied as conditional formatting from A2 to E12 and will highlight the left-hand (fruit) cell of inconsistent pair of cells.
Then you can use a similar formula to highlight the right-hand cell of each pair:-
=SUM(ISEVEN(COLUMN())*($A$2:$E$12=A2)*($B$2:$F$12<>B2))
Apply this from B2 to F12.
Note that Smango are highlighted because they are in an inconsistent group (although they are also in a consistent group).
Here is the alternative approach (as suggested) of highlighting the consistent groups:-
The formulae are
=SUM(ISODD(COLUMN())*($A$2:$E$12=A2)*($B$2:$F$12=B2))>1
and
=SUM(ISEVEN(COLUMN())*($A$2:$E$12=A2)*($B$2:$F$12=B2))>1
to be applied as before.
The sum this time will always be at least one because each pair of cells will match with itself, so the '>' sign is to find if there are any matches with other pairs of cells.

image uploaded to database but unable to display the image

Im using the simpleform to upload the file image
<tr>
<td align="right">Photo</td>
<td><input type="file"size="30" name="photo" /></td>
</tr>
then here is my php file..Im using mysql_fetch_array
row[6] is my photo...
// retrieves a row data and returns it as an associative array
while($row=mysql_fetch_array($result)){
echo "<table border='1' align='center' class='table_background'>
<tr>
<td align='left' width=100>UserName=</td>
<td align='left' width='400'></td>
</tr>
<tr>
<td align='left' width=100>Title=</td>
<td align='left' width='400'>$row[1]</td>
</tr>
<tr>
<td align='left'width=100>Category=</td>
<td align='left'width='400'>$row[2]</td>
</tr>
<tr>
<td align='left'width=100>Description=</td>
<td align='left'width='400'>$row[3]</td>
</tr>
<tr>
<td align='left'width=100>State=</td>
<td align='left'width='400'>$row[4]</td>
</tr>
<tr>
<td align='left'width=100>Photo=</td>
<td align='left'width='400'>$row[5]</td>
</tr>
<tr>
<td align='left'width=100>Date=</td>
<td align='left'width='200'>$row[6]</td>
</tr>
<br>
}
<br>
<br>
</table>";
}
In my database I use Blob as the type of image ... the image is successful upload to my database
but just display the image file name...
blob is a string so you have to display id a bit different
echo '<img src="data:image/jpeg;base64,'.base64_encode( $row[6] ).'"/>';