How to stop other conditional formatting from disappearing when hackmodding databars into solid fills? - xlsx

EPPlus has no support for extLst thing which is needed to make databars conditional formatting with solid fill. They are gradient by themselves without modifications.
I coded this to modify worksheet's xml directly (this gets databars from worksheet XML and then adds required extLst nodes):
public static Random Rnd = new Random();
public static string GenerateXlsId()
{
//{29BD882A-B741-482B-9067-72CC5D939236}
string id = string.Empty;
for (int i = 0; i < 32; i++)
if (Rnd.NextDouble() < 0.5)
id += Rnd.Next(0, 10);
else
id += (char)Rnd.Next(65, 91);
id = id.Insert(8, "-");
id = id.Insert(13, "-");
id = id.Insert(18, "-");
id = id.Insert(23, "-");
return id;
}
public static void FixDatabarsAtWorksheet(OfficeOpenXml.ExcelWorksheet eworksheet)
{
System.Xml.XmlNodeList databars = eworksheet.WorksheetXml.GetElementsByTagName("dataBar");
if (databars.Count > 0)
{
string conditional_formattings_str = string.Empty;
for (int i = 0; i < databars.Count; i++)
{
string temp_databar_id = GenerateXlsId();
databars[i].ParentNode.InnerXml += #"<extLst>
<ext uri=""{B025F937-C7B1-47D3-B67F-A62EFF666E3E}"" xmlns:x14=""http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"">
<x14:id>{" + temp_databar_id + #"}</x14:id>
</ext>
</extLst>";
//--
string temp_sqref = databars[i].ParentNode.ParentNode.Attributes["sqref"].Value;
string left_type = string.Empty;
string left_val = string.Empty;
string right_type = string.Empty;
string right_val = string.Empty;
string color = string.Empty;
Color databar_fill_color = Color.Empty;
Color databar_border_color = Color.Empty;
for (int j = 0; j < databars[i].ChildNodes.Count; j++)
if (databars[i].ChildNodes[j].LocalName == "cfvo" && databars[i].ChildNodes[j].Attributes["type"] != null)
{
if (string.IsNullOrEmpty(left_type))
left_type = databars[i].ChildNodes[j].Attributes["type"].Value;
else if (string.IsNullOrEmpty(right_type))
right_type = databars[i].ChildNodes[j].Attributes["type"].Value;
if (databars[i].ChildNodes[j].Attributes["val"] != null)
if (string.IsNullOrEmpty(left_val))
left_val = databars[i].ChildNodes[j].Attributes["val"].Value;
else if (string.IsNullOrEmpty(right_val))
right_val = databars[i].ChildNodes[j].Attributes["val"].Value;
}
else if (databars[i].ChildNodes[j].LocalName == "color")
{
color = databars[i].ChildNodes[j].Attributes["rgb"].Value;
int argb = Int32.Parse(color, System.Globalization.NumberStyles.HexNumber);
databar_fill_color = Color.FromArgb(argb);
databar_border_color = Color.FromArgb(255,
databar_fill_color.R - 50 < 0 ? databar_fill_color.R + 50 : databar_fill_color.R - 50,
databar_fill_color.G - 50 < 0 ? databar_fill_color.R + 50 : databar_fill_color.G - 50,
databar_fill_color.B - 50 < 0 ? databar_fill_color.R + 50 : databar_fill_color.B - 50);
}
string temp_conditional_formatting_template = #"<x14:conditionalFormatting xmlns:xm=""http://schemas.microsoft.com/office/excel/2006/main"">
<x14:cfRule type=""dataBar"" id=""{" + temp_databar_id + #"}"">
<x14:dataBar minLength=""" + (string.IsNullOrEmpty(left_val) ? "0" : left_val) + "\" maxLength=\"" + (string.IsNullOrEmpty(right_val) ? "100" : right_val) + "\" gradient=\"0\" " + (databar_border_color.IsEmpty ? string.Empty : "border = \"1\"") + ">";
temp_conditional_formatting_template += Environment.NewLine + "<x14:cfvo type=\"" + (left_type.ToLower() == "min" ? "autoMin" : left_type) + "\" />";
temp_conditional_formatting_template += Environment.NewLine + "<x14:cfvo type=\"" + (right_type.ToLower() == "max" ? "autoMax" : right_type) + "\" />";
if (!databar_border_color.IsEmpty)
temp_conditional_formatting_template += Environment.NewLine + "<x14:borderColor rgb=\"" + BitConverter.ToString(new byte[] { databar_border_color.A, databar_border_color.R, databar_border_color.G, databar_border_color.B }).Replace("-", "") + "\" />";
temp_conditional_formatting_template += Environment.NewLine + #"</x14:dataBar>
</x14:cfRule>
<xm:sqref>" + temp_sqref + #"</xm:sqref>
</x14:conditionalFormatting>";
conditional_formattings_str += temp_conditional_formatting_template;
}
databars[0].ParentNode.ParentNode.ParentNode.InnerXml += #"<extLst>
<ext uri=""{78C0D931-6437-407d-A8EE-F0AAD7539E65}"" xmlns:x14=""http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"">
<x14:conditionalFormattings>" + conditional_formattings_str + #"
</x14:conditionalFormattings>
</ext>
</extLst>";
}
}
And this really makes databars solid fill, the problem is any other conditional formatting like GreaterThan loses it's style when true.
For example I add databar and GreaterThan 123 (green) conditional formattings.
Excel still see coditional formatting rule GreaterThan 123, but the style is not set when it's true (green is not set). While databars is displayed correctly at same time.
I don't know where to look... Someone help!

Thats the problem with hacks - they are so fragile! :)
I was able to get it work with another hack - setting the style differential formatting (dxf) reference which seems to be dropped when epplus saves. What might be happening is epplus only thinks there is one dxf on save so it doesnt set the value since excel will assume it is the first dxf style (index 0) but that is a bit of a guess.
Anyway, if you set the dxfid via XML manually it will find it. But order counts here, you have to apply the databar hack last otherwise it will hit the wrong reference:
[TestMethod]
public void FixDatabarsAtWorksheetTest()
{
//https://stackoverflow.com/questions/58417819/how-to-stop-other-conditional-formatting-from-disappearing-when-hackmodding-data
//Throw in some data
var datatable = new DataTable("tblData");
datatable.Columns.AddRange(new[]
{
new DataColumn("Col1", typeof(int)), new DataColumn("Col2", typeof(int)), new DataColumn("Col3", typeof(object))
});
for (var i = 0; i < 10; i++)
{
var row = datatable.NewRow();
row[0] = i;
row[1] = i * 10;
row[2] = Path.GetRandomFileName();
datatable.Rows.Add(row);
}
//Create a test file
var fi = new FileInfo(#"c:\temp\FixDatabarsAtWorksheetTest.xlsx");
if (fi.Exists)
fi.Delete();
using (var pck = new ExcelPackage(fi))
{
var workbook = pck.Workbook;
var doc = workbook.Worksheets.Add("Sheet1");
doc.Cells.LoadFromDataTable(datatable, true);
//Set the greater than
var gtConditional = doc
.ConditionalFormatting
.AddGreaterThan(doc.Cells["A2:A11"]);
gtConditional.Formula = "2";
gtConditional.Style.Fill.BackgroundColor.Color = Color.GreenYellow;
//Fix the gt
var xdoc = doc.WorksheetXml;
var nsm = new XmlNamespaceManager(xdoc.NameTable);
nsm.AddNamespace("default", xdoc.DocumentElement.NamespaceURI);
var gtNode = xdoc.SelectSingleNode("/default:worksheet/default:conditionalFormatting[#sqref=\"A2:A11\"]", nsm);
//Create the new attribute for table
var att = xdoc.CreateAttribute("dxfId");
att.Value = "0";
gtNode
.FirstChild
.Attributes.Append(att);
//Set the bar condition LAST
var barConditional = doc
.ConditionalFormatting
.AddDatabar(doc.Cells["B2:B11"], Color.FromArgb(99, 195, 132));
barConditional.HighValue.Type = eExcelConditionalFormattingValueObjectType.Num;
barConditional.LowValue.Type = eExcelConditionalFormattingValueObjectType.Num;
barConditional.HighValue.Value = 82;
barConditional.LowValue.Value = 0;
FixDatabarsAtWorksheet(doc);
pck.Save();
}
}
I get this:
Not sure how feasible this is for you depending on how many conditional formats you have but its worth a shot.

Related

Looking for a solution to replace tags in a loop where template also contains tables

I have the following docx file:
%LOOP=PolicyRelationship,NAME=Life,KEY=(PolicyNo=Policy.PolicyNo,Relation='INSR')%
%Life.EntityNo% - %Life.Name1% %Life.Name2%
%ENDLOOP%
The following is a table with a header row
Cover Type Sum Insured Modal Premium
BenefitVal SumValue ModalValue
This is the last line of the document.
I am looping through LOOP blocks iteratively - replacing each variable with data
All remaining text is being cut from wordDoc and pasted to remainingParagraphs then re-pasted at the end after the loop values have been pasted back in
Not all paragraphs are being processed this way due to the condition
if (wordDoc.Paragraphs[i].ParentContainer == Container.Body)
condition. Without this condition all paragraphs are processed in the right order but the XML is corrupt. With this condition the table values are not transferred and thus appear incorrectly BEFORE the loop values.
If there is a simpler approach without all the cutting and pastings that would be ideal
This is my current code snippet:
private void ProcessRepeatingText(DocX wordDoc, Dictionary<string, DocumentView> views)
{
var textDoc = wordDoc.Text;
var opn = 0;
while (opn != -1)
{
int cls, cma;
string tag, dto, rsn, key, where;
object repo;
//
// Get each loop DataView that has been defined, select a collection of data and store it in "views"
//
opn = textDoc.IndexOf("%LOOP=", StringComparison.OrdinalIgnoreCase);
if (opn == -1) break;
cls = textDoc.IndexOf("%", opn + 1, StringComparison.OrdinalIgnoreCase);
tag = textDoc.Substring(opn, cls - opn + 1);
cma = tag.IndexOf(",", StringComparison.OrdinalIgnoreCase);
dto = tag.Substring(6, cma - 6);
opn = tag.IndexOf("NAME=", cma, StringComparison.OrdinalIgnoreCase);
cls = tag.IndexOf(",", opn + 5, StringComparison.OrdinalIgnoreCase);
rsn = tag.Substring(opn + 5, cls - opn - 5);
cma = tag.IndexOf(",", cls, StringComparison.OrdinalIgnoreCase);
opn = tag.IndexOf("KEY=(", cma, StringComparison.OrdinalIgnoreCase);
cls = tag.IndexOf(")", opn + 4, StringComparison.OrdinalIgnoreCase);
key = tag.Substring(opn + 5, cls - opn - 5);
where = BuildWhereClause(dto, key, views);
repo = _baseRepository.CreateInstance(dto + "Repository");
var sec = repo.GetType().GetMethod("GetWhere").Invoke(repo, new object[] { where });
views.Add(rsn, new DocumentView { Rsn = rsn, Dto = dto, Data = sec, Pointer = 0 });
var loopTag = tag;
var i = -1;
var startAt = 0;
var tagBlocks = new List<TagBlock>();
opn = textDoc.IndexOf(loopTag, StringComparison.OrdinalIgnoreCase);
while (opn != -1)
{
if (textDoc.Substring(opn, 6) == "%LOOP=")
{
i++;
cls = textDoc.IndexOf("%", opn + 1, StringComparison.OrdinalIgnoreCase);
tagBlocks.Add(new TagBlock { From = opn, Upto = -1, FromIndex = -1, UptoIndex = -1 });
tagBlocks[i].FromIndex = IndexOfParagraph(wordDoc, textDoc.Substring(opn, cls - opn + 1), ref startAt);
opn = opn + 6;
}
if (textDoc.Substring(opn, 8) == "%ENDLOOP")
{
tagBlocks[i].Upto = opn;
if (tagBlocks[i].FromIndex != -1)
{
tagBlocks[i].UptoIndex = IndexOfParagraph(wordDoc, textDoc.Substring(opn, 9), ref startAt);
}
i--;
opn = opn + 8;
}
if (i == -1) break;
opn++;
}
var remainingParagraphs = new List<Novacode.Paragraph>();
for (i = tagBlocks[0].UptoIndex + 1; i < wordDoc.Paragraphs.Count; i++)
{
// if (wordDoc.Paragraphs[i].ParentContainer == ContainerType.Body)
// {
remainingParagraphs.Add(wordDoc.Paragraphs[i]);
wordDoc.RemoveParagraphAt(i);
i--;
// }
}
var loopDoc = DocX.Create(new MemoryStream());
if (tagBlocks[0].FromIndex != -1)
{
if (tagBlocks[0].UptoIndex != -1)
{
for (i = tagBlocks[0].FromIndex + 1; i < tagBlocks[0].UptoIndex; i++)
{
loopDoc.InsertParagraph(wordDoc.Paragraphs[i]);
}
for (i = tagBlocks[0].UptoIndex; i > tagBlocks[0].FromIndex; i--)
{
wordDoc.RemoveParagraphAt(i);
}
}
wordDoc.RemoveParagraphAt(tagBlocks[0].FromIndex);
}
else
{
opn = tagBlocks[0].From;
cls = textDoc.IndexOf("%", opn + 1, StringComparison.OrdinalIgnoreCase);
tag = textDoc.Substring(opn, cls - opn + 1);
var paragraph = wordDoc.Paragraphs.FirstOrDefault(x => x.Text.Contains(tag));
if (paragraph != null)
{
paragraph.ReplaceText(tag, "");
paragraph.ReplaceText("%ENDLOOP%", "");
}
}
var loopTxt = loopDoc.Text;
//
// Now get the secondary DataView data from "views"
//
DocumentView view;
if (views.TryGetValue(rsn, out view) != true)
{
return;
}
view.Pointer = 0;
var list = (IList)view.Data;
for (view.Pointer = 0; view.Pointer < list.Count; view.Pointer++)
{
var item = list[view.Pointer];
//
// Process conditional text, with a dependency on this secondary RSN, within this loop
//
loopTxt = ProcessConditionalText(loopDoc, view.Rsn, views, loopTxt);
//
// Process repeating text (LOOP..ENDLOOP) with a dependency on this secondary RSN
//
ProcessRepeatingText(loopDoc, views);
//
// Perform the data tag replacements, for this RSN, within this loop
//
ReplaceParameters(loopDoc, item, view.Rsn);
foreach (var p in loopDoc.Paragraphs)
{
wordDoc.InsertParagraph(p);
}
}
foreach (var p in remainingParagraphs)
{
wordDoc.InsertParagraph(p);
}
wordDoc.Paragraphs.FirstOrDefault(p => p.Text == loopTag)?.Remove(false);
wordDoc.ReplaceText(loopTag, "");
textDoc = wordDoc.Text;
views.Remove(rsn);
opn = 0;
}
}

Text one, two three etc in Angular automatically

I have the following snippet of code that creates 1, 2, 3 etc based on the number in parent repeat (All good).
{{$index+1}}
But I am looking for Text such as One, Two Three etc
Is there a way to achieve this in Angular? (Text instead of numerics)
One solution is to create a filter, for example:
// Script.js
angular.module('app')
.filter('numberToWord', function() {
return function( s ) {
var th = ['','thousand','million', 'billion','trillion'];
var dg = ['zero','one','two','three','four', 'five','six','seven','eight','nine'];
var tn = ['ten','eleven','twelve','thirteen', 'fourteen','fifteen','sixteen', 'seventeen','eighteen','nineteen'];
var tw = ['twenty','thirty','forty','fifty', 'sixty','seventy','eighty','ninety'];
s = s.toString();
s = s.replace(/[\, ]/g,'');
if (s != parseFloat(s)) return 'not a number';
var x = s.indexOf('.');
if (x == -1) x = s.length;
if (x > 15) return 'too big';
var n = s.split('');
var str = '';
var sk = 0;
for (var i=0; i < x; i++)
{
if ((x-i)%3==2)
{
if (n[i] == '1')
{
str += tn[Number(n[i+1])] + ' ';
i++;
sk=1;
}
else if (n[i]!=0)
{
str += tw[n[i]-2] + ' ';
sk=1;
}
}
else if (n[i]!=0)
{
str += dg[n[i]] +' ';
if ((x-i)%3==0) str += 'hundred ';
sk=1;
}
if ((x-i)%3==1)
{
if (sk) str += th[(x-i-1)/3] + ' ';
sk=0;
}
}
if (x != s.length)
{
var y = s.length;
str += 'point ';
for (var i=x+1; i<y; i++) str += dg[n[i]] +' ';
}
return str.replace(/\s+/g,' ');
};
})
And then you can use it like this:
{{$index | numberToWord }}
Edit: An example Plunker http://plnkr.co/edit/DIQ3YVkH7N6PUaqju82X?p=preview
There is no standard feature in Angular for that. Here is a link to a great algorithm to convert number to word Developers blog - Convert Numbers into Words Using JavaScript
Put the algorithm in a function and use it like this :
{{convertNumberToWord($index+1)}}
Here is a working example in Plunker for your situation

accessing array elements in another frame as3

I have created an Array in frame 1 and dynamically create a list of movieclips with it , and I want to create the same Array in frame 3 and those movieclips again if something is true or false.is it possible ? because when I'm trying to do this , I will get this error :
1151: A conflict exists with definition i in namespace internal.
here is my code at frame 1 :
stop();
import flash.display.MovieClip;
var p_x:uint = 90;
var p_y:uint = 108;
var my_list:String = "Games,Videos, Medias,Images,Photos,Personal Photos,Social Media,Private,Social,None,Names,Families";
var myListString:Array = my_list.split(",");
var myArray:Array=new Array ();
var listObject = 1;
for (var i:uint=0; i<12; i++)
{
var myItemList:mrb=new mrb();
myItemList.x = p_x;
myItemList.y = p_y + 80;
myItemList.y = (p_y + (listObject * 65));
myArray.push(myItemList);
myItemList.txt.text = i.toString();
myItemList.txt.text = myListString[i].toString();
myItemList.name = "item"+i;
addChild(myItemList) as MovieClip ;
listObject++;
}
and here is code at frame 3 :
var tmpCurFrame:int = currentFrame;
this.addEventListener(Event.ENTER_FRAME, handleUpdate)
function handleUpdate(e:Event):void {
if (tmpCurFrame != currentFrame) {
this.removeEventListener(Event.ENTER_FRAME, handleUpdate);
return;
}
if (so.data.fav1 != undefined)
{
if ( so.data.fav1 == "on")
{
for (var i:int = 0; i < myListString.length;)
{ if (myListString[i].indexOf() > -1)
{
var myRectangle:mrb=new mrb();
trace("found it at index: " + i);
myRectangle.x = p_x;
myRectangle.y = (p_y + (findobject * 50));
trace('p_y+80 =' + (p_y+(findobject*80)) + 'p_x = ' + p_x );
myArray.push(myRectangle);
myRectangle.txt.text = myListString[i].toString();
trace(my_array2[i].toString() );
addChild(myRectangle);
}
}
}
}
else
{
fav_1.fav_on.visible=true;
}
}
This error message simply means that you use twice the same variable i. You just have to give them differents names.

Batch file to compare two different files having different data

I want to compare both files, if data is not matched, then print a message "DATA is not the same" and, if they match successfully, print "DATA is the same".
Content of First File (Live.txt):
Last
4000
5000
(2 Row affected)
Content Second File(Sup.txt) :
Last
3000
6000
(2 Row affected)
OS: Windows7
On Microsoft Windows you can use fc command.
On Linux and similar systems
cmp <file1> <file2>
will tell you if the files are different and:
diff <file1> <file2>
will show the differences.
we can also write large files byte by byte with a particular layout and fill the differences in the excel
import java.awt.image.SampleModel;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class FlatFileComparator {
/*
* Get the three flat files.
*
* One for Layout, Second for Expected File Third for Actual file
*/
public static void main(String args[]) throws Exception {
String fileName = "recordLayout.txt";
String actualFileName = "Actual.txt";
String expectedFileName = "Expected.txt";
List<String> recordLayout = null;
FlatFileComparator fb = new FlatFileComparator();
recordLayout = fb.getFileLayout(fileName);
fb.compareExpectedActual(actualFileName, expectedFileName, recordLayout);
}
// Get the Record Names of the Layout and put it in the List with the Field
// Name, Start Index and End Index
public List<String> getFileLayout(String layoutFileName) throws Exception {
List<String> fileLayoutList = new ArrayList<String>();
File layoutFile = new File(layoutFileName);
FileInputStream layoutFileInputStream = new FileInputStream(layoutFile);
BufferedReader layoutBuffReader = new BufferedReader(
new InputStreamReader(layoutFileInputStream));
String currentLine;
try {
while ((currentLine = layoutBuffReader.readLine()) != null) {
if ((currentLine.trim().equals(""))) {
throw new Exception(
"There should not be any empty lines in the middle of the Layout File");
}
String fieldName = currentLine.substring(0,
currentLine.indexOf(":"));
String startIndex = currentLine.substring(
currentLine.indexOf(":") + 2, currentLine.indexOf(","));
String endIndex = currentLine.substring(
currentLine.indexOf(",") + 1,
currentLine.lastIndexOf(")"));
fileLayoutList.add(fieldName);
fileLayoutList.add(startIndex);
fileLayoutList.add(endIndex);
// System.out.println(fieldName);
}
} catch (IOException e) {
// TODO Auto-generated catch block
throw new Exception(
"You have not provided the Layout File for processing. Please provide it and try again");
}
return fileLayoutList;
}
// Get the Actual and Expected File and compare according to the position
public void compareExpectedActual(String actualFileName,
String expectedFileName, List<String> fileLayoutList)
throws Exception {
File actualFile = new File(actualFileName);
File expectedFile = new File(expectedFileName);
FileInputStream actualFileInputStream = new FileInputStream(actualFile);
BufferedReader actBuffReader = new BufferedReader(
new InputStreamReader(actualFileInputStream));
FileInputStream expectedFileInputStream = new FileInputStream(
expectedFile);
BufferedReader expBuffReader = new BufferedReader(
new InputStreamReader(expectedFileInputStream));
HSSFWorkbook excelWorkbook = new HSSFWorkbook();
HSSFSheet excelSheet = excelWorkbook.createSheet("File Comparator");
HSSFRow headerExcelRow = excelSheet.createRow(1);
HSSFRow currExcelRow = null;
HSSFCell headerExcelCell = null;
HSSFCell currExcelCell = null;
headerExcelCell = headerExcelRow.createCell(1);
headerExcelCell.setCellValue("Field Name");
for (int fieldName = 2, listNum = 0; listNum < fileLayoutList.size(); fieldName++) {
currExcelRow = excelSheet.createRow(fieldName);
currExcelCell = currExcelRow.createCell(1);
// System.out.println(listNum);
currExcelCell.setCellValue(fileLayoutList.get(listNum));
listNum += 3;
}
System.out.println(fileLayoutList.size());
int excelNum = 2;
for (String actualFileCurrLine, expectedFileCurrLine; (actualFileCurrLine = actBuffReader
.readLine()) != null
&& (expectedFileCurrLine = expBuffReader.readLine()) != null; excelNum += 4) {
char[] actualArray = actualFileCurrLine.toCharArray();
char[] expectedArray = expectedFileCurrLine.toCharArray();
for (int i = 0, excelRow = 2; i < fileLayoutList.size(); i += 3, excelRow++) {
boolean resultOfCompare = false;
String expectedString = "";
String actualString = "";
for (int j = Integer.parseInt(fileLayoutList.get(i + 1)); j <= Integer
.parseInt(fileLayoutList.get(i + 2)); j++) {
expectedString += expectedArray[j - 1];
// System.out.println("Array Index"+j);
System.out.println(fileLayoutList.get(i + 1));
System.out.println(fileLayoutList.get(i + 2));
actualString += actualArray[j - 1];
}
if (expectedString.equals(actualString))
resultOfCompare = true;
System.out.println(expectedString + "-" + actualString);
System.out.println("Row Number" + excelRow);
headerExcelCell = headerExcelRow.createCell(excelNum);
headerExcelCell.setCellValue("Actual");
headerExcelCell = headerExcelRow.createCell(excelNum + 1);
headerExcelCell.setCellValue("Expected");
headerExcelCell = headerExcelRow.createCell(excelNum + 2);
headerExcelCell.setCellValue("Result");
System.out.println("Cell Value" + "[" + excelRow + ","
+ excelNum + "]=" + actualString);
currExcelRow = excelSheet.getRow(excelRow);
currExcelCell = currExcelRow.createCell(excelNum);
currExcelCell.setCellValue(actualString);
System.out.println("Cell Value" + "[" + excelRow + ","
+ (excelNum + 1) + "]=" + actualString);
currExcelCell = currExcelRow.createCell(excelNum + 1);
currExcelCell.setCellValue(expectedString);
System.out.println("Cell Value" + "[" + excelRow + ","
+ (excelNum + 2) + "]=" + resultOfCompare);
currExcelCell = currExcelRow.createCell(excelNum + 2);
currExcelCell.setCellValue(resultOfCompare);
}
}
FileOutputStream s = new FileOutputStream("FlatfileComparator.xls");
excelWorkbook.write(s);
}
}

Store Image in DataTable

I want to store image into my datatable and while adding colum I want to set its default value, sending you code doing with checkboxes..
public void addCheckBoxesRuntime(){
for (int i = 0; i < InformationOne.Length; i++)
{
dt = new DataColumn(InformationOne[i][1] + " (" + InformationOne[i][0] + " )");
dt.DataType = typeof(Boolean);
viewDataTable.Columns.Add(dt);
dt.DefaultValue = false;
}
}
Make a DataColumn with type string and then store the string binary of the image into the field. Alternatively, use the binary itself with a byte[].
Should work 100%.
Something along the lines of this:
public string ImageConversion(System.Drawing.Image image)
{
if (image == null)
return string.Empty;
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Gif);
string value = string.Empty;
for (int intCnt = 0; intCnt <= memoryStream.ToArray.Length - 1; intCnt++)
{
value = value + memoryStream.ToArray(intCnt) + ",";
}
return value;
}
}

Resources