Сообщество

How to customize a export result instead of standard export setting?

Hi all,

In the DocDef editor export setting, I use advanced filename template:\ as path I need. As the image "origin.png", I don't want table is separate to another folder. So I uncheck the separate file option.

But, as my attachment image, there is my document section structure(1.png), I have one InvoiceNo, one TotalAmount and 4 repeating items for this sample. If I creat a single XLS, it will get a result(2.png) that InvoiceNo and TotalAmount are printed 4 times. How can I get InvoiceNo and TotalAmount just one time(3.png) Or like (4.png) result with simplest way? If it is difficult to realize(need to assembly excel language which I don't know how to use), How about separate to the same folder? Thanks.

Была ли эта статья полезной?

Пользователи, считающие этот материал полезным: 0 из 0

Комментарии

Комментариев: 17

  • Avatar
    Timur
    Hello

    When you export documents with repeatable groups FlexiCapture maps all repeatening instance to the intance of the root element.
    In order to get a results in format similar tp 4.png you will need to use a custom export script.

    As a workaround you can consider exporting repeatable elements to a diffrent file. In order to do so, go to your export options and open Data format options.
    Check options "Make separate items for repeatable items", but as you noticed by choosing this option repeatable elements are put to subfolder. This behavior cannot be overridden using standard functionality.

    Regards
    Tim


    0
  • Avatar
    Ivan
    Hi Timur,

    Is it need to assembly Excel language?Or only use export script can achieve independently? Thanks!
    0
  • Avatar
    Timur
    Yes, you will need to use Microsoft Excel libraries and a programming language of choice (C# VB etc)
    0
  • Avatar
    Ivan
    Hi Timur,

    I study the FC11 help in You are here: Appendix > Using scripts in ABBYY FlexiCapture > External Assemblies
    But, I still can't figure out how can assembly Excel. Is there any extra sample can refer?
    Thanks!
    0
  • Avatar
    Timur
    Hello,

    Abby help file conatins only infromation about how to load an external assembly in your flexicapture project.

    For this you need to open project properties and go to .net references, from there you can load an assembly.
    Note that flexi capture 11 supports only assemblies compiled .net 4.0 or older.

    After you have added the assemby you need to go to your document definition and open Document definition properties where you have to do the same procedure of adding the assembly from your projects' shared assemblies.

    After you have added the assembly to your document definition it is ready to be used in your export or rule scripts.

    Code should start simliar to the following(C#):
    using Microsoft.Office.Interop

    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
    Object oMissing = System.Reflection.Missing.Value;
    Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
    Microsoft.Office.Interop.Excel.Workbook xlWorkBook = xlApp.Workbooks.Add(oMissing);

    Try searching for more examples of how to use excel assembly to create your export script.

    Regards,
    Tim








    0
  • Avatar
    Ivan
    Hi Timur,

    I install and have the file "Microsoft.Office.Interop.dll", and then, I add this attached file in .Net References.
    I also test some Excel's operation in VS2008(C#), it can work well.
    But, I get some errors when paste your code even my code in export script.

    Microsoft.Office.Interop.Excel.Application xapp = new Microsoft.Office.Interop.Excel.Application();
    xapp.Application.Workbooks.Add(true);
    Microsoft.Office.Interop.Excel.Worksheet xsheet = (Microsoft.Office.Interop.Excel.Worksheet)xapp.Sheets[1];
    xsheet.Name = "Sheet1";
    xsheet.Cells[1, 1] = "123";
    string filepath = "test.xls";
    xsheet.SaveAs(filepath, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, true, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing);
    xapp.Workbooks.Close();
    xapp.Quit();

    What's the problem I can't work in script editor? Thanks
    0
  • Avatar
    Timur
    Hello,

    Try saving the document definition and publishing it in order to make your document definition be aware that the dll is attached.

    Could you provide full export script for review?

    Regards
    Tim







    0
  • Avatar
    Ivan
    Hi Timur,

    I have published DocDef now, I only test your code to check whether it can run. It's sorry that errors windows is printed in Chinese Traditional, I don't know how to change languages.
    0
  • Avatar
    Timur
    In order to change language go to system registry HKEY_CURRENT_USER\Software\ABBYY\FlexiCapture\11.0\Fine Objects and change InterfaceLanguage to 0.

    As for the code provided earlier it's not a working solution, but just a sample of how it should look like.

    Check the sample provided in the following link:
    http://www.dotnetperls.com/excel

    Regards
    Tim








    0
  • Avatar
    Ivan
    Hi Timur,

    My registry value is 0 already, but it still display in Chinese Traditional.
    I think it has different style of writing between "Script in DocDef" and "Export Global Script Module/Rule Global Script Module", even if use in the same C# language.
    So, I always can't test successfully from past experience. It seems that Export Script should need a namespace/class... to be beginning.
    I have a further question is whether I can use Context.Field("fieldname") to get text in Export Global Script Module.
    0
  • Avatar
    Timur
    Another thing you can check is your language and region settings to resolve issue with chinese letters.

    If your OS is chinese that also might be a possible reason for this beahvior.

    Theres is no need to use namepaces in an export script, errors are probably due to passing incorrect parameters:

    using System;
    using Microsoft.Office.Interop.Excel;

    Object oMissing = System.Reflection.Missing.Value;
    Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
    Microsoft.Office.Interop.Excel.Workbook xlWorkBook = xlApp.Workbooks.Add(oMissing);
    Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBo ok.Worksheets.get_Item(1);
    XlSaveAsAccessMode AccessMode = XlSaveAsAccessMode.xlNoChange;
    //SaveAs(object Filename, object FileFormat, object Password, object WriteResPassword, object ReadOnlyRecommended, object CreateBackup, XlSaveAsAccessMode AccessMode = XlSaveAsAccessMode.xlNoChange, object ConflictResolution = null, object AddToMru = null, object TextCodepage = null, object TextVisualLayout = null, object Local = null);
    //Close(object SaveChanges, object Filename, object RouteWorkbook);
    xlWorkBook.SaveAs("asd.xls",oMissing,oMissing,oMis sing,oMissing,oMissing,AccessMode,oMissing,oMissin g,oMissing,oMissing,oMissing);


    check the commented strings, they show which parameters should be passed.

    Regards
    Tim


    IN order to access fields from export you need to access Document.Field
    0
  • Avatar
    Ivan
    Hi Timur,

    Thanks for your patient with my poor knowledge in advance. But I still have errors in (line4,pos1) and (line5,pos56).
    1.A namespace cannot directly contain members such as fields or methods(line4,pos1)
    2.Expected class, delegate, enum, interface, or struct(line5,pos56)

    0
  • Avatar
    Timur
    Hello,

    It's hard to tell where the mistake is from screenshots.

    Check sample project:https://www.dropbox.com/s/shflh3w9ftsml8l/ExcelSample.zip?dl=0

    It contains a working script to excel

    Regards,
    Tim


    0
  • Avatar
    Ivan
    Hi Timur,

    I think I use a wrong script in DocDef editor. In your project, it is add a custom export(script) in export settings. But I always use script modules-> export script(Export Global Script Module) to edit. With your sample, I think I can start to modify to what I need now. Thanks for your help!
    0
  • Avatar
    Ivan
    Hi Timur,

    Sorry, I have a further question need to ask you. How can I get the source_filename in export script? Just like export path template .
    Otherwise, it seems that file will be re-written each time.
    0
  • Avatar
    Timur
    If you are using Global script module then you have to define a namespace for your classes. Then you need to add this namespace in your export script in order to have access to them.

    Regards
    Tim




    0
  • Avatar
    Ivan
    Hi Timur

    I have a last question at #16, can you help me? Thanks.
    0

Войдите в службу, чтобы оставить комментарий.