Hi,
If you call targetrange.Copy(sourcerange),
there are source and target files together in the memory. I am afraid, we have no good idea
for this.
Could you import CSV file to workbook and
apply some formatting to the cells?
For example:
private void Test01_ImportCSV()
{
try
{
StartTest("Test01_ImportCSV");
var book = new Workbook();
Range targetRange = null;
//Open text file
book.Open(txtSourceFile.Text, ',');
WriteOutput("CSV file opened");
//If file couldn't be parsed, exception is thrown)
if (book.Worksheets[0] == null) throw new Exception("Couldn't parse text file");
//Create range from all text file data
var sourceRange =
book.Worksheets[0].Cells.CreateRange(0, 0, book.Worksheets[0].Cells.MaxDataRow
+ 1, book.Worksheets[0].Cells.MaxDataColumn + 1);
WriteOutput("Opened CSV file's worksheet");
if (sourceRange == null)
throw new Exception("Couldn't
create source range in text file");
//Get the target workbook
var targetworkbook = new
Workbook();
targetworkbook.Open(txtTargetFile.Text);
WriteOutput("Opened target workbook");
//Getting target sheet
var sheet = targetworkbook.Worksheets[0];
WriteOutput("Extracted target worksheet");
targetRange = sheet.Cells.CreateRange(0, 0, book.Worksheets[0].Cells.MaxDataRow
+ 1, book.Worksheets[0].Cells.MaxDataColumn + 1);
WriteOutput("Created target range");
////Copy cell data from a source ranges
//targetRange.Copy(sourceRange);
sourceRange.CopyStyle(targetRange);
WriteOutput("Copied CSV data to target");
book.Save(txtTargetFile.Text);
WriteOutput("Saved workbook");
targetRange = null; targetworkbook = null;
FinishTest();
}
catch (Exception
ex)
{
HandleException("Importing a CSV file", ex);
}
}
Thank you.