Hi,
Here I am trying to insert data into an existing excel template. The data is in .tcv file. Is it possible to insert this data into the excel without tampering the format of the excel?
I have attached the sample excel file and the .tcv file, for the sake of reference.
Thanks
Kunal
Hi,
Well, you need to get values/data from your .tcv file and then paste values to their relevant pointer in your existing template Excel file.
e.g
string filename = @“e:\test2\SampleTCVData.tcv”;
Workbook wb = new Workbook(filename, new LoadOptions(LoadFormat.TabDelimited));
Worksheet ws = wb.Worksheets[0];
ExportTableOptions options = new ExportTableOptions();
options.SkipErrorValue = true;
options.ExportColumnName = true;
DataTable dt = ws.Cells.ExportDataTable(0, 0, ws.Cells.MaxDataRow+1, ws.Cells.MaxDataColumn+1,options);
Workbook workbook = new Workbook(“e:\test2\InvoiceImageSample.xls”);
Worksheet worksheet = workbook.Worksheets[0];
FindOptions findOptions = new FindOptions();
findOptions.CaseSensitive = false;
//Insert value from field “” to the related pointer in the destination file.
//This works fine.
Aspose.Cells.Cell foundCell = worksheet.Cells.FindString(“”, null, findOptions);
worksheet.Cells.ImportDataColumn(dt,false,foundCell.Row,foundCell.Column,“”,false);
Style style = foundCell.GetStyle();
style.Custom = “m/d/yyyy”;
foundCell.SetStyle(style);
foundCell = worksheet.Cells.FindString(“”, null, findOptions);
worksheet.Cells.ImportDataColumn(dt, false, foundCell.Row, foundCell.Column, “”, false); //This shows odd characters i.e. “�����s���ԍ�1"<br> <br>//Even I tried:<br> MessageBox.Show(dt.Rows[0]["<The Text of Address with KANJI:String>"].ToString()); //also shows "�����s�
��ԍ�1”
//you may do the operation for other fields.
workbook.Save(“e:\test2\outFile.xls”);
Another alternative would be using Smart markers feature, you can place markers in your template file and then process markers based on the data source and paste values for the pointers. See the topic:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/smart-markers.html
Moreover, there is an issue regarding your language characters in the template .tcv file when parsing to datatable, we need to investigate if this is an issue with the product or something else. Or we can adopt some other options for your requirement, so the language char sets would be implemented fine.
We will get back to you soon.
Thank you.
Hi,
In the meanwhile, I have logged an issue with an id: CELLSNET-22949. We will investigate it and let you know about it soon.
Thank you.
Hi,
After analyzing your case, we think we cannot support your desired feature (import data from .tcv file).
It’s a better solution( as per my suggestion) i.e…, converting the file to a table, then process it with smart markers.
Sorry for any inconvenience caused!
<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman","serif";}
<![endif]–>