Skip to content

Commit 562f7c2

Browse files
committed
fix bug with binary scripting to Excel formatting
1 parent ee4230b commit 562f7c2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Code/TSqlFlex.Core/FieldScripting.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,16 @@ public static string getDataAsDateFormat(object data)
555555
}
556556

557557
public static string getDataAsBinaryFormat(object data, object[] fieldInfo)
558+
{
559+
int fieldLength = (int)fieldInfo[(int)FieldScripting.FieldInfo.FieldLength];
560+
return getDataAsBinaryFormat(data, fieldLength);
561+
}
562+
563+
public static string getDataAsBinaryFormat(object data, int fieldLength)
558564
{
559565
byte[] ba = (byte[])data;
560566
string bitsAsHexString = BitConverter.ToString(ba).Replace("-", "");
561-
int charCountToShowAsHex = (int)fieldInfo[(int)FieldScripting.FieldInfo.FieldLength] * 2;
567+
int charCountToShowAsHex = fieldLength * 2;
562568
bitsAsHexString = bitsAsHexString.PadLeft(charCountToShowAsHex, '0');
563569
return "0x" + bitsAsHexString;
564570
}

Code/TSqlFlex.Core/XmlSpreadsheetRenderer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static void renderAsXMLSpreadsheet(FlexResultSet resultSet, SqlRunParamet
3939
srp.WriteToStream("<Row>");
4040
for (int colIndex = 0; colIndex < columnCount; colIndex += 1)
4141
{
42+
//todo: fix each of these items to work with the actual scripting stuff (requires finishing major refactoring work).
4243
object fieldData = result.data[rowIndex][colIndex];
4344
string fieldTypeName = result.schema.Rows[colIndex].ItemArray[(int)FieldScripting.FieldInfo.DataType].ToString();
4445
if (fieldData == null || fieldData is DBNull)
@@ -57,6 +58,11 @@ public static void renderAsXMLSpreadsheet(FlexResultSet resultSet, SqlRunParamet
5758
((DateTime)fieldData).ToString("yyyy-MM-ddTHH:mm:ss.fff")
5859
)));
5960
}
61+
else if (fieldTypeName == "binary" || fieldTypeName == "rowversion" || fieldTypeName == "timestamp")
62+
{
63+
byte[] d = (byte[])result.data[rowIndex][colIndex];
64+
srp.WriteToStream(String.Format("<Cell ss:StyleID=\"s64\"><Data ss:Type=\"String\">{0}</Data></Cell>\r\n", escapeForXML(FieldScripting.getDataAsBinaryFormat(d,d.Length))));
65+
}
6066
else
6167
{
6268
srp.WriteToStream(String.Format("<Cell ss:StyleID=\"s64\"><Data ss:Type=\"String\">{0}</Data></Cell>\r\n", escapeForXML(result.data[rowIndex][colIndex].ToString())));

0 commit comments

Comments
 (0)