int row = 1;
//int colm = 1;int colm = 676; // Width of image file
Excel.Application objApp;
Excel._Workbook objBook;
Excel.Workbooks wrkbook;
Excel._Worksheet wrksheet;
Excel.Sheets sheets;
Excel.Range range;
Excel.Range one_cel;
objApp = new Excel.Application();
wrkbook = objApp.Workbooks;
objBook = wrkbook.Add(Missing.Value);
sheets = objBook.Worksheets;
object misValue = System.Reflection.Missing.Value;
wrksheet = (Excel._Worksheet)sheets.get_Item(1);
range = wrksheet.get_Range("A1", Missing.Value);
range = range.get_Resize(200, 2000);
range.ColumnWidth = 1;
range.RowHeight = 10;
string line;
int l_hex_ctr;
char l_match_color;
int temp_index = 0;
byte byte_val;
byte[] array_ads = new byte[16];
int ads_tempctr;
byte_val = (byte)(0);
ads_tempctr = 0;
l_match_color = '0';
FileStream fs = new FileStream(g_bitmap_file + ".txt", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
long l_file_len = fs.Length;
while (g_line_ctr > 0)
{
line = sr.ReadLine();
string[] l_hex_arr = line.Split(',');
l_match_color = '0';
for (l_hex_ctr = 0; l_hex_ctr < l_hex_arr.Length; l_hex_ctr++)
{
if (l_hex_arr[l_hex_ctr].Length > 1)
{
if (l_hex_arr[l_hex_ctr] == "FF")
{
//l_match_color = '0';
}
else
{
l_match_color = '1';
}
}
}
//Console.WriteLine(line + " - " + l_match_color.ToString());
if (l_match_color == '1')
{
switch (temp_index)
{
case 0: byte_val = (byte)(byte_val + 1);
break;
case 1: byte_val = (byte)(byte_val + 2);
break;
case 2: byte_val = (byte)(byte_val + 4);
break;
case 3: byte_val = (byte)(byte_val + 8);
break;
case 4: byte_val = (byte)(byte_val + 16);
break;
case 5: byte_val = (byte)(byte_val + 32);
break;
case 6: byte_val = (byte)(byte_val + 64);
break;
case 7: byte_val = (byte)(byte_val + 128);
break;
}
}
if (++temp_index == 8)
{
// wr_fl.Write(byte_val);
array_ads[ads_tempctr] = (byte)(byte_val);
temp_index = 0;
byte_val = (byte)(0);
if (++ads_tempctr > 15)
{
//for (ads_tempctr = 15; ads_tempctr >= 0; ads_tempctr--)
//{
// //wr_fl.Write(array_ads[ads_tempctr]);
// //Console.Write(array_ads[ads_tempctr]);
// //Console.Write(",");
//}
//Console.WriteLine(" ");
ads_tempctr = 0;
}
}
switch (l_match_color)
{
case '0':
//colm = colm + 1;
colm = colm - 1;
break;
case '1':
one_cel = (Excel.Range)wrksheet.Cells[row, colm];
one_cel.Interior.ColorIndex = 21;
//colm = colm + 1;
colm = colm - 1;
break;
}
//if (colm >= 128)
if (colm <= 0)
{
//row = row + 1;
row = row + 1;
//colm = 1;
colm = 676; // Width of image file
}
if (row > 17)
{
//break;
}
l_file_len--;
g_line_ctr--;
}
//objApp.Visible = true;
int l_index = g_bitmap_file.IndexOf('.');
string l_filename = g_bitmap_file.Substring(0, l_index);
objBook.SaveAs(l_filename + ".xlsx", Excel.XlFileFormat.xlWorkbookDefault, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
//objApp.UserControl = true;
objApp.Quit();
//GC.Collect();
}
Join the conversation! Your thoughts help the community grow.