Parsing Calendar blob from Oracle Primavera using Javascript - javascript

Oracle Primavera stores Calendar data as blob in base64 encoded format, which when decoded gives the following content,
(0||CalendarData()( (0||DaysOfWeek()( (0||1()()) (0||2()( (0||0(s|08:00|f|16:00)()))) (0||3()( (0||0(s|08:00|f|16:00)()))) (0||4()( (0||0(s|08:00|f|16:00)()))) (0||5()( (0||0(s|08:00|f|16:00)()))) (0||6()( (0||0(s|08:00|f|16:00)()))) (0||7()()))) (0||VIEW(ShowTotal|Y)()) (0||Exceptions()( (0||0(d|39814)()) (0||1(d|39815)()) (0||2(d|39818)()) (0||3(d|39819)()) (0||4(d|39820)()) (0||5(d|39821)()) (0||6(d|39822)()) (0||7(d|39825)()) (0||8(d|39826)()) (0||9(d|39827)()) (0||10(d|39828)()) (0||11(d|39829)()) (0||12(d|39832)()) (0||13(d|39833)()) (0||14(d|39834)()) (0||15(d|39835)()) (0||16(d|39836)()) (0||17(d|39839)()) (0||18(d|39840)()) (0||19(d|39841)()) (0||20(d|39842)()) (0||21(d|39843)()) (0||22(d|39846)()) (0||23(d|39847)()) (0||24(d|39848)()) (0||25(d|39849)()) (0||26(d|39850)()) (0||27(d|39853)()) (0||28(d|39854)()) (0||29(d|39855)()) (0||30(d|39856)()) (0||31(d|39857)()) (0||32(d|39860)()) (0||33(d|39861)()) (0||34(d|39862)()) (0||35(d|39863)()) (0||36(d|39864)()) (0||37(d|39867)()) (0||38(d|39868)()) (0||39(d|39869)()) (0||40(d|39870)()) (0||41(d|39871)()) (0||42(d|39874)()) (0||43(d|39875)()) (0||44(d|39876)()) (0||45(d|39877)()) (0||46(d|39878)()) (0||47(d|39881)()) (0||48(d|39882)()) (0||49(d|39883)()) (0||50(d|39884)()) (0||51(d|39885)()) (0||52(d|39888)()) (0||53(d|39889)()) (0||54(d|39890)()) (0||55(d|39891)()) (0||56(d|39892)()) (0||57(d|39895)()) (0||58(d|39896)()) (0||59(d|39897)()) (0||60(d|39898)()) (0||61(d|39899)()) (0||62(d|39902)()) (0||63(d|39903)()) (0||64(d|39923)()) (0||65(d|39958)()) (0||66(d|39997)()) (0||67(d|40063)()) (0||68(d|40098)()) (0||69(d|40128)()) (0||70(d|40133)()) (0||71(d|40134)()) (0||72(d|40135)()) (0||73(d|40136)()) (0||74(d|40137)()) (0||75(d|40140)()) (0||76(d|40141)()) (0||77(d|40142)()) (0||78(d|40143)()) (0||79(d|40144)()) (0||80(d|40147)()) (0||81(d|40148)()) (0||82(d|40149)()) (0||83(d|40150)()) (0||84(d|40151)()) (0||85(d|40154)()) (0||86(d|40155)()) (0||87(d|40156)()) (0||88(d|40157)()) (0||89(d|40158)()) (0||90(d|40161)()) (0||91(d|40162)()) (0||92(d|40163)()) (0||93(d|40164)()) (0||94(d|40165)()) (0||95(d|40168)()) (0||96(d|40169)()) (0||97(d|40170)()) (0||98(d|40171)()) (0||99(d|40172)()) (0||100(d|40175)()) (0||101(d|40176)()) (0||102(d|40177)()) (0||103(d|40178)()) (0||104(d|40179)()) (0||105(d|40182)()) (0||106(d|40183)()) (0||107(d|40184)()) (0||108(d|40185)()) (0||109(d|40186)()) (0||110(d|40189)()) (0||111(d|40190)()) (0||112(d|40191)()) (0||113(d|40192)()) (0||114(d|40193)()) (0||115(d|40196)()) (0||116(d|40197)()) (0||117(d|40198)()) (0||118(d|40199)()) (0||119(d|40200)()) (0||120(d|40203)()) (0||121(d|40204)()) (0||122(d|40205)()) (0||123(d|40206)()) (0||124(d|40207)()) (0||125(d|40210)()) (0||126(d|40211)()) (0||127(d|40212)()) (0||128(d|40213)()) (0||129(d|40214)()) (0||130(d|40217)()) (0||131(d|40218)()) .....
How can I read the dates from this variable ? I need to convert it into JSON to be used by the script. I need all the exceptions - the value and date ( For instance, 131 is the exception and 40218 is the date ). Thank you,

This is how I did this in PHP
Parse the data with a nested parenthesis class
https://gist.github.com/Xeoncross/4710324
Then deal with the time intervals
if( preg_match('~^s\|([0-9]+):([0-9]+)\|f\|([0-9]+):([0-9]+)$~', $string, $match) )
{ // Start and finish times
$interval[] = array(
's' => array(
't' => $match[1].':'.$match[2],
'h' => (int)$match[1],
'm' => (int)$match[2],
),
'f' => array(
't' => $match[3].':'.$match[4],
'h' => (int)$match[3],
'm' => (int)$match[4],
)
);
}

MPXJ reads this data. The relevant code can be found starting here https://github.com/joniles/mpxj/blob/master/src/net/sf/mpxj/primavera/PrimaveraReader.java#L181 which I suspect you can translate easily enough into Javascript.

Related

I can't decode a url encoded in unknow format on an ASP site

I'm scraping through a website and this website has a form the form is in the Arabic language so it's encoding everything (inputs) to let the form get work properly
MY problem is I'm scraping using JS and decodeUri/decodeUriComponent not working with the encoding output string that coming from the site.
even the browser says unable to decode value in console dev
the link example that I need to get it decoded:
http://app2.helwan.edu.eg/HelwanNat/Education/TermAlist.asp?x_level=2020%2D2019&z_level=LIKE&x_dep=%C7%E1%DA%E1%E6%E3+%2D%CA%DA%E1%ED%E3+%C7%D3%C7%D3%EC&z_dep=LIKE&x_st_name=%E3%CD%E3%CF&z_st_name=LIKE
This appears to be a windows-1256 encoding.
You can decode it in js like so:
function decode(string) {
var array = [...string.matchAll(/%(.{2})/g)].map((groups) => parseInt(groups[1], 16));
var decoder = new TextDecoder('windows-1256');
return decoder.decode(Uint8Array.from(array).buffer);
}
console.log(decode('%E3%CD%E3%CF'));
console.log('%C7%E1%DA%E1%E6%E3+%2D%CA%DA%E1%ED%E3+%C7%D3%C7%D3%EC'.split('+').map(decode));
Since TextEncoder() can only encode utf-8 strings, you will have to make a conversion table for windows-1256:
windows_1256 = [
'\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', '\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F',
'\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', '\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F',
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
'\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F',
'\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F',
'\u20AC', '\u067E', '\u201A', '\u0192', '\u201E', '\u2026', '\u2020', '\u2021', '\u02C6', '\u2030', '\u0679', '\u2039', '\u0152', '\u0686', '\u0698', '\u0688',
'\u06AF', '\u2018', '\u2019', '\u201C', '\u201D', '\u2022', '\u2013', '\u2014', '\u06A9', '\u2122', '\u0691', '\u203A', '\u0153', '\u200C', '\u200D', '\u06BA',
'\u00A0', '\u060C', '\u00A2', '\u00A3', '\u00A4', '\u00A5', '\u00A6', '\u00A7', '\u00A8', '\u00A9', '\u06BE', '\u00AB', '\u00AC', '\u00AD', '\u00AE', '\u00AF',
'\u00B0', '\u00B1', '\u00B2', '\u00B3', '\u00B4', '\u00B5', '\u00B6', '\u00B7', '\u00B8', '\u00B9', '\u061B', '\u00BB', '\u00BC', '\u00BD', '\u00BE', '\u061F',
'\u06C1', '\u0621', '\u0622', '\u0623', '\u0624', '\u0625', '\u0626', '\u0627', '\u0628', '\u0629', '\u062A', '\u062B', '\u062C', '\u062D', '\u062E', '\u062F',
'\u0630', '\u0631', '\u0632', '\u0633', '\u0634', '\u0635', '\u0636', '\u00D7', '\u0637', '\u0638', '\u0639', '\u063A', '\u0640', '\u0641', '\u0642', '\u0643',
'\u00E0', '\u0644', '\u00E2', '\u0645', '\u0646', '\u0647', '\u0648', '\u00E7', '\u00E8', '\u00E9', '\u00EA', '\u00EB', '\u0649', '\u064A', '\u00EE', '\u00EF',
'\u064B', '\u064C', '\u064D', '\u064E', '\u00F4', '\u064F', '\u0650', '\u00F7', '\u0651', '\u00F9', '\u0652', '\u00FB', '\u00FC', '\u200E', '\u200F', '\u06D2'
];
function encode(string){
return [...string].map(c => `%${windows_1256.indexOf(c).toString(16).toUpperCase()}`).join('');
}
console.log(encode('محمد'));
console.log(['العلوم', "-تعليم", "اساسى"].map(encode).join('+'));

CRC-16-IBM implementation (JS) not working

Background
I receive a buffer of bytes that has a CRC check at the end. According to the manual, this is the CRC-16-IBM algorithm with the polynomial 0xA001 ( reversed as seen in Wikipedia ).
Research
To implement this I translated code from several SO questions from Java to C# into JS but nothing seems to work and I have no idea why.
Code
Here is the implementation I am currently dealing with:
const crc16ibm = buffer => {
const table = [
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
];
let crc = 0x0000;
for( const byte of buffer ){
crc = crc >>> 8 ^ table[ ( crc ^ byte ) & 0xff ];
}
return crc;
};
module.exports = crc16ibm;
Here is a test that is supposed to work:
const hexStr = Buffer.from( "000000000000001C0D01050000001056E924222347455420444154414F524445520D0A01", "hex");
const expectedCrc = 0x00004990;
assert( crc16ibm( hexStr ), expectedCrc ); //NOPE!
What is wrong?
I have quite literally tried everything, but either the examples I am using to test my code are wrong, or I have no idea on what's going on. At this point I weight both equally.
Is the problem with the lookup table?
The manual provides a graphic with an image of a ( quite inefficient ) possible way to implement this, via repeated for loops instead of using a table:
But I would much rather use a table and find out what is actually wrong in my current algorithm...
There's nothing wrong with your table or code to compute the CRC described in the flow chart. There must be something wrong with your test vector.
I did this and it worked
const crc16ibm = buffer => {
const table = [
0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
];
let crc = 0x0000;
for( const byte of buffer ){
crc = crc >>> 8 ^ table[ ( crc ^ byte ) & 0xff ];
}
return crc;
};
module.exports.crc16ibm = crc16ibm;
This is how yo can try it
/*
const crc16ibm= require("./crc16ibm").crc16ibm; console.log((crc16ibm(Buffer.from('0C010500000007676574696E666F01','hex'))).toString(16));
*/

laravel getting error on empty request

I get error below while trying to add item to my cart:
Darryldecode \ Cart \ Exceptions \ InvalidItemException
validation.numeric
The error comes from this part of my code:
$customAttributes = [];
if(!empty($request->attr)){
foreach($request->attr as $sub) {
// find the suboption
$sub = Suboption::find($sub);
if (!empty($sub->id)) {
$itemCondition1 = new \Darryldecode\Cart\CartCondition(array(
'name' => $sub->title,
'value' => $sub->price,
'type' => 'additional',
'target' => 'item',
));
array_push($customAttributes, $itemCondition1);
}
}
}
and it take place in here:
Cart::add(array(
'id' => $product->id,
'name' => $product->title,
'price' => $price,
'quantity' => $request->input('quantity'),
'attributes' => $weightArray,
'conditions' => $customAttributes, //here
));
The $customAttributes code supposed to get data IF product does have those information And user chose any of it and suppose to ignore if product doesn't have any of those info or user didn't chose any of it.
Issue is
The code expect data no matter what, product does have that info or not, user selected any or not, even if user select that data still i get error above.
Demo
https://imgur.com/a/KHJqp
any idea why is that?
UPDATE
I figured my issue comes from 'price' => $price, in my add method where i get my $price like:
$price = $product->discounts;
if($price->count() > 0 ) {
foreach($discounts as $disc){
if($disc->value_to >= $mytime) {
$price = $product->price - $disc->amount;
}
}
}else{
$price = $product->price;
}
this part supposed to get product price if there is no discount, and get discounted price if there is.
How I get to this line of code? here is it
SOLVED
I used hidden field and got my data from front-end instead of controller method.

How to get .on("change") to work with gldatepicker?

I have a date select box that when a date is selected, the date will be used in a calculation.
<? echo $this->Form->input( 'start_date', array( 'label' => __('Show only accounts made since:'), 'value' => '', 'readonly' => 'readonly' ) ); ?>
The Javascript I tried:
$('#start_date').glDatePicker({ cssName: 'darkneon'});
$("#start_date").on("change",function() {
var date = this.value;
console.log (date);
do_stuff(date);
});
The console shows nothing when I select a date. I am clearly missing something. Is on-change even the right way to handle this?
Try this:
$('#start_date').glDatePicker({
cssName: 'darkneon',
onClick: function(target, cell, date, data) {
console.log (date);
do_stuff(date);
}
);
From the docs (find with Ctrl+f):
Callback that will trigger when the user clicks a selectable date.
Example (check example #3)

PHPExcel - Render HTML markups on output

In my site I have several forms using CKEditor to store it's data. So when I export all the content, in excel I can see markups all over my document. Is there an easy way to convert those to \n or somehow have PHPExcel recognize them as breaks?
I also tried changing the export type to Excel2007 thinking that maybe Excel could just simply render the HTML markup, however when I switch types my report just crashes. So im sticking with Excel5.
Any help would be appreciated.
<?php
/** PHPExcel */
require_once '/Excelphp/Classes/PHPExcel.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
$rows=2;
$sheet=$objPHPExcel->getActiveSheet();
// Set properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");
//This is the hard coded *non dynamic* cell formatting
$sheet->getColumnDimension('A')->setWidth(5);
$sheet->getColumnDimension('B')->setWidth(15);
$sheet->getColumnDimension('C')->setWidth(50);
$sheet->getColumnDimension('D')->setWidth(50);
$sheet->getSheetView()->setZoomScale(90);
$sheet->getStyle('A:D') ->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
//Font Setting for the Support group title.
$Support_team = array('font'=> array('bold'=> true,'color' => array('rgb' => '4D4D4D'),'size' => 22,'name' => 'Arial'),'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER),);
//Font settings for the header cells only.
$headers = array('font'=> array('bold'=> true,'color' => array('rgb' => '4D4D4D'),'size' => 12,'name' => 'Arial'),'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER),);
//Border settings
$borders = array('borders' => array('inside'=> array('style' => PHPExcel_Style_Border::BORDER_THIN,'color' => array('argb' => '717171')),'outline' => array('style' => PHPExcel_Style_Border::BORDER_THIN,'color' => array('argb' => '717171'))));
// SQl database connections
$db = mysql_connect("localhost", "IMC_COE2", "IMC123");
mysql_select_db("IMC_COE2",$db);
$sql="select client, team_name,support_team_prime,prime_comments,support_team_backup,backup_comments,escalation1,escalation1_comments,escalation2,escalation2_comments,escalation3,escalation3_comments,escalation4,escalation4_comments,note from tbl_address ORDER BY team_name";
$result=mysql_query($sql);
$numrows=mysql_num_rows($result);
if ($numrows>0)
{
while($data=mysql_fetch_array($result))
{
//Cell Merging
$sheet
->mergeCells('B'.$rows.':D'.$rows)
->mergeCells('B'.($rows+2).':D'.($rows+2))
->mergeCells('B'.($rows+5).':D'.($rows+5))
->mergeCells('B'.($rows+10).':D'.($rows+10))
->mergeCells('C'.($rows+1).':D'.($rows+1))
->mergeCells('B'.($rows+11).':D'.($rows+11));
// Add some data
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('B'.($rows+1), 'Client:')
->setCellValue('B'.($rows+2), 'Support group contacts')
->setCellValue('B'.($rows+3), 'Prime:')
->setCellValue('B'.($rows+4), 'Backup:')
->setCellValue('B'.($rows+5), 'Escalations')
->setCellValue('B'.($rows+6), 'Escalation 1:')
->setCellValue('B'.($rows+7), 'Escalation 2:')
->setCellValue('B'.($rows+8), 'Escalation 3:')
->setCellValue('B'.($rows+9), 'Escalation 4:')
->setCellValue('B'.($rows+10), 'Notes');
//Format the hardcoded text
$sheet->getStyle('B'.$rows)->applyFromArray($Support_team);
$sheet->getStyle('B'.($rows+2))->applyFromArray($headers);
$sheet->getStyle('B'.($rows+5))->applyFromArray($headers);
$sheet->getStyle('B'.($rows+10))->applyFromArray($headers);
//Row height adjustments
$sheet->getRowDimension($rows+3)->setRowHeight(60);
$sheet->getRowDimension($rows+4)->setRowHeight(60);
$sheet->getRowDimension($rows+6)->setRowHeight(60);
$sheet->getRowDimension($rows+7)->setRowHeight(60);
$sheet->getRowDimension($rows+8)->setRowHeight(60);
$sheet->getRowDimension($rows+9)->setRowHeight(60);
$sheet->getRowDimension($rows+11)->setRowHeight(100);
//Cell Wraptext
$sheet->getStyle('C'.($rows+1).':D'.($rows+1))->getAlignment()->setWrapText(true);
$sheet->getStyle('C'.($rows+3).':D'.($rows+3))->getAlignment()->setWrapText(true);
$sheet->getStyle('C'.($rows+4).':D'.($rows+4))->getAlignment()->setWrapText(true);
$sheet->getStyle('C'.($rows+6).':D'.($rows+6))->getAlignment()->setWrapText(true);
$sheet->getStyle('C'.($rows+7).':D'.($rows+7))->getAlignment()->setWrapText(true);
$sheet->getStyle('C'.($rows+8).':D'.($rows+8))->getAlignment()->setWrapText(true);
$sheet->getStyle('C'.($rows+9).':D'.($rows+9))->getAlignment()->setWrapText(true);
$sheet->getStyle('B'.($rows+11).':D'.($rows+11))->getAlignment()->setWrapText(true);
//Background color on cells
$sheet->getStyle('B'.$rows.':D'.$rows)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF9BC2E6');
$sheet->getStyle('B'.($rows+2).':D'.($rows+2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF9BC2E6');
$sheet->getStyle('B'.($rows+5).':D'.($rows+5))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF9BC2E6');
$sheet->getStyle('B'.($rows+10).':D'.($rows+10))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF9BC2E6');
$sheet->getStyle('B'.($rows+1))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FFE6F1FA');
$sheet->getStyle('B'.($rows+3))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FFE6F1FA');
$sheet->getStyle('B'.($rows+4))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FFE6F1FA');
$sheet->getStyle('B'.($rows+6))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FFE6F1FA');
$sheet->getStyle('B'.($rows+7))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FFE6F1FA');
$sheet->getStyle('B'.($rows+8))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FFE6F1FA');
$sheet->getStyle('B'.($rows+9))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FFE6F1FA');
//Border range
$sheet->getStyle('B'.$rows.':D'.($rows+11))->applyFromArray($borders);
//This section is the actual data imported from the SQL database *don't touch*
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('C'.($rows+1), utf8_encode($data['client'])) //this will give cell C2.
->setCellValue('B'.$rows, utf8_encode($data['team_name'])) // this will give cell B2
->setCellValue('C'.($rows+3), utf8_encode($data['support_team_prime'])) //this will give C5
->setCellValue('D'.($rows+3), utf8_encode($data['prime_comments'])) // This will give D5
->setCellValue('C'.($rows+4), utf8_encode($data['support_team_backup'])) //This will give C6
->setCellValue('D'.($rows+4), utf8_encode($data['backup_comments'])) //This will give D6
->setCellValue('C'.($rows+6), utf8_encode($data['escalation1']))//THis will give you C8
->setCellValue('D'.($rows+6), utf8_encode($data['escalation1_comments']))//This will give you D8
->setCellValue('C'.($rows+7), utf8_encode($data['escalation2']))//This will give you C9
->setCellValue('D'.($rows+7), utf8_encode($data['escalation2_comments']))//This will give you D9
->setCellValue('C'.($rows+8), utf8_encode($data['escalation3']))//This will give you C10
->setCellValue('D'.($rows+8), utf8_encode($data['escalation3_comments']))//This will give you D10
->setCellValue('C'.($rows+9), utf8_encode($data['escalation4']))//This will give you C11
->setCellValue('D'.($rows+9), utf8_encode($data['escalation4_comments']))//This will give you D11
->setCellValue('B'.($rows+11), utf8_encode($data['note'])); //This will give you B13
$rows+=14;
}
}
// Rename sheet
$sheet->setTitle('Directory Tool Full dump');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client’s web browser (Excel5)
ob_end_clean();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
header('Content-Type: application/vnd.ms-excel');
$today=date("F.d.Y");
$filename = "Directory_Export-$today.xls";
header("Content-Disposition: attachment; filename=$filename");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
$objWriter->save('php://output');
exit;
?>
MS Excel has no concept of HTML Markup within a cell, it's simply a string value.... storing a value like ABC<br />DEF will simply be treated as a string containing ABC<br />DEF and not as two lines containing ABC and DEF respectively. If you want it to be treated as two lines then you need to change the <br /> to "\n". You also need to set the cell alignment to wrap.

Categories

Resources