public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            // Load only specific sheets with data and formulas
            // Other objects, items etc. would be discarded

            // Instantiate LoadOptions specified by the LoadFormat
            LoadOptions loadOptions7 = new LoadOptions(LoadFormat.Xlsx);

            // Set the LoadDataOption
            LoadDataOption dataOption = new LoadDataOption();

            // Specify the sheet(s) in the template file to be loaded
            dataOption.SheetNames    = new string[] { "Sheet2" };
            dataOption.ImportFormula = true;
            // Only data and formatting should be loaded.
            loadOptions7.LoadDataAndFormatting = true;
            // Specify the LoadDataOption
            loadOptions7.LoadDataOptions = dataOption;

            // Create a Workbook object and opening the file from its path
            Workbook wb = new Workbook(dataDir + "Book1.xlsx", loadOptions7);

            Console.WriteLine("File data imported successfully!");
            // ExEnd:1
        }
示例#2
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");
            //Define a new Workbook.
            Workbook workbook;

            //Set the load data option with selected sheet(s).
            LoadDataOption dataOption = new LoadDataOption();

            dataOption.SheetNames = new string[] { "Sheet2" };

            //Load the workbook with the spcified worksheet only.
            LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);

            loadOptions.LoadDataOptions       = dataOption;
            loadOptions.LoadDataAndFormatting = true;

            //Creat the workbook.
            workbook = new Workbook(dataDir + "TestData.xlsx", loadOptions);

            //Perform your desired task.

            //Save the workbook.
            workbook.Save(dataDir + "outputFile.xlsx");
        }
示例#3
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir    = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            string sampleFile = "output.xlsx";
            string samplePath = dataDir + sampleFile;

            // Create a sample workbook
            // and put some data in first cell of all 3 sheets
            Workbook createWorkbook = new Workbook();

            createWorkbook.Worksheets["Sheet1"].Cells["A1"].Value     = "Aspose";
            createWorkbook.Worksheets.Add("Sheet2").Cells["A1"].Value = "Aspose";
            createWorkbook.Worksheets.Add("Sheet3").Cells["A1"].Value = "Aspose";
            createWorkbook.Worksheets["Sheet3"].IsVisible             = false;
            createWorkbook.Save(samplePath);

            // Load the sample workbook
            LoadDataOption loadDataOption = new LoadDataOption();

            loadDataOption.OnlyVisibleWorksheet = true;
            LoadOptions loadOptions = new LoadOptions();

            loadOptions.LoadDataAndFormatting = true;
            loadOptions.LoadDataOptions       = loadDataOption;

            Workbook loadWorkbook = new Workbook(samplePath, loadOptions);

            Console.WriteLine("Sheet1: A1: {0}", loadWorkbook.Worksheets["Sheet1"].Cells["A1"].Value);
            Console.WriteLine("Sheet1: A2: {0}", loadWorkbook.Worksheets["Sheet2"].Cells["A1"].Value);
            Console.WriteLine("Sheet1: A3: {0}", loadWorkbook.Worksheets["Sheet3"].Cells["A1"].Value);
            // ExEnd:1
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            string sampleFile = "Sample.out.xlsx";
            string samplePath = dataDir + sampleFile;

            // Create a sample workbook
            // and put some data in first cell of all 3 sheets
            Workbook createWorkbook = new Workbook();
            createWorkbook.Worksheets["Sheet1"].Cells["A1"].Value = "Aspose";
            createWorkbook.Worksheets.Add("Sheet2").Cells["A1"].Value = "Aspose";
            createWorkbook.Worksheets.Add("Sheet3").Cells["A1"].Value = "Aspose";
            createWorkbook.Worksheets["Sheet3"].IsVisible = false;
            createWorkbook.Save(samplePath);

            // Load the sample workbook
            LoadDataOption loadDataOption = new LoadDataOption();
            loadDataOption.OnlyVisibleWorksheet = true;
            LoadOptions loadOptions = new LoadOptions();
            loadOptions.LoadDataAndFormatting = true;
            loadOptions.LoadDataOptions = loadDataOption;

            Workbook loadWorkbook = new Workbook(samplePath, loadOptions);
            Console.WriteLine("Sheet1: A1: {0}", loadWorkbook.Worksheets["Sheet1"].Cells["A1"].Value);
            Console.WriteLine("Sheet1: A2: {0}", loadWorkbook.Worksheets["Sheet2"].Cells["A1"].Value);
            Console.WriteLine("Sheet1: A3: {0}", loadWorkbook.Worksheets["Sheet3"].Cells["A1"].Value);
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            // Load only specific sheets with data and formulas
            // Other objects, items etc. would be discarded

            // Instantiate LoadOptions specified by the LoadFormat
            LoadOptions loadOptions7 = new LoadOptions(LoadFormat.Xlsx);

            // Set the LoadDataOption
            LoadDataOption dataOption = new LoadDataOption();
            // Specify the sheet(s) in the template file to be loaded
            dataOption.SheetNames = new string[] { "Sheet2" };
            dataOption.ImportFormula = true;
            // Only data and formatting should be loaded.
            loadOptions7.LoadDataAndFormatting = true;
            // Specify the LoadDataOption
            loadOptions7.LoadDataOptions = dataOption;

            // Create a Workbook object and opening the file from its path
            Workbook wb = new Workbook(dataDir + "Book1.xlsx", loadOptions7);
            Console.WriteLine("File data imported successfully!");
            // ExEnd:1
            
            }
        public static void Main()
        {
            //ExStart:1
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            //Define a new Workbook.
            Workbook workbook;

            //Set the load data option with selected sheet(s).
            LoadDataOption dataOption = new LoadDataOption();

            dataOption.SheetNames = new string[] { "Sheet2" };

            //Load the workbook with the spcified worksheet only.
            LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);

            loadOptions.LoadDataOptions       = dataOption;
            loadOptions.LoadDataAndFormatting = true;

            //Creat the workbook.
            workbook = new Workbook(dataDir + "TestData.xlsx", loadOptions);

            //Perform your desired task.

            //Save the workbook.
            workbook.Save(dataDir + "outputFile.out.xlsx");
            //ExEnd:1
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            // Define a new Workbook.
            Workbook workbook;

            // Set the load data option with selected sheet(s).
            LoadDataOption dataOption = new LoadDataOption();
            dataOption.SheetNames = new string[] { "Sheet2" };

            // Load the workbook with the spcified worksheet only.
            LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);
            loadOptions.LoadDataOptions = dataOption;
            loadOptions.LoadDataAndFormatting = true;

            // Creat the workbook.
            workbook = new Workbook(dataDir+ "TestData.xlsx", loadOptions);

            // Perform your desired task.

            // Save the workbook.
            workbook.Save(dataDir+ "outputFile.out.xlsx");
            // ExEnd:1
            
        }
示例#8
0
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            //Output directory
            string outputDir = RunExamples.Get_OutputDirectory();

            // Open the template file
            Workbook book = new Workbook(sourceDir + "sampleRemoveWhitespaceAroundData.xlsx");

            // Get the first worksheet
            Worksheet      sheet      = book.Worksheets[0];
            LoadDataOption dataOption = new LoadDataOption();
            LoadOptions    options    = new LoadOptions();

            options.LoadFilter = new LoadFilter(LoadDataFilterOptions.All);
            // Specify your print area if you want
            // Sheet.PageSetup.PrintArea = "A1:H8";

            // To remove the white border around the image.
            sheet.PageSetup.LeftMargin   = 0;
            sheet.PageSetup.RightMargin  = 0;
            sheet.PageSetup.BottomMargin = 0;
            sheet.PageSetup.TopMargin    = 0;

            // Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

            imgOptions.ImageType = Drawing.ImageType.Emf;

            // Set only one page would be rendered for the image
            imgOptions.OnePagePerSheet = true;
            imgOptions.PrintingPage    = PrintingPageType.IgnoreBlank;

            // Create the SheetRender object based on the sheet with its
            // ImageOrPrintOptions attributes
            SheetRender sr = new SheetRender(sheet, imgOptions);

            // Convert the image
            sr.ToImage(0, outputDir + "outputRemoveWhitespaceAroundData.emf");

            Console.WriteLine("RemoveWhitespaceAroundData executed successfully.");
        }
        public static void Run()
        {
            // Exstart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            
            

            // 1.
            // Opening through Path
            // Creating a Workbook object and opening an Excel file using its file path
            Workbook workbook1 = new Workbook(dataDir + "Book1.xls");
            Console.WriteLine("Workbook opened using path successfully!");


            // 2.
            // Opening through Stream
            // Create a Stream object
            FileStream fstream = new FileStream(dataDir + "Book2.xls", FileMode.Open);

            // Creating a Workbook object, open the file from a Stream object
            // That contains the content of file and it should support seeking
            Workbook workbook2 = new Workbook(fstream);
            Console.WriteLine("Workbook opened using stream successfully!");
            fstream.Close();


            // 3.
            // Opening Microsoft Excel 97 - 2003 Files
            // Get the Excel file into stream
            FileStream stream = new FileStream(dataDir + "Book_Excel97_2003.xls", FileMode.Open);

            // Instantiate LoadOptions specified by the LoadFormat.
            LoadOptions loadOptions1 = new LoadOptions(LoadFormat.Excel97To2003);

            // Create a Workbook object and opening the file from the stream
            Workbook wbExcel97 = new Workbook(stream, loadOptions1);
            Console.WriteLine("Microsoft Excel 97 - 2003 workbook opened successfully!");


            // 4.
            // Opening Microsoft Excel 2007 Xlsx Files
            // Instantiate LoadOptions specified by the LoadFormat.
            LoadOptions loadOptions2 = new LoadOptions(LoadFormat.Xlsx);

            // Create a Workbook object and opening the file from its path
            Workbook wbExcel2007 = new Workbook(dataDir + "Book_Excel2007.xlsx", loadOptions2);
            Console.WriteLine("Microsoft Excel 2007 workbook opened successfully!");


            // 5.
            // Opening SpreadsheetML Files
            // Instantiate LoadOptions specified by the LoadFormat.
            LoadOptions loadOptions3 = new LoadOptions(LoadFormat.SpreadsheetML);

            // Create a Workbook object and opening the file from its path
            Workbook wbSpreadSheetML = new Workbook(dataDir + "Book3.xml", loadOptions3);
            Console.WriteLine("SpreadSheetML file opened successfully!");


            // 6.
            // Opening CSV Files
            // Instantiate LoadOptions specified by the LoadFormat.
            LoadOptions loadOptions4 = new LoadOptions(LoadFormat.CSV);

            // Create a Workbook object and opening the file from its path
            Workbook wbCSV = new Workbook(dataDir + "Book_CSV.csv", loadOptions4);
            Console.WriteLine("CSV file opened successfully!");


            // 7.
            // Opening Tab Delimited Files
            // Instantiate LoadOptions specified by the LoadFormat.
            LoadOptions loadOptions5 = new LoadOptions(LoadFormat.TabDelimited);

            // Create a Workbook object and opening the file from its path
            Workbook wbTabDelimited = new Workbook(dataDir + "Book1TabDelimited.txt", loadOptions5);
            Console.WriteLine("Tab delimited file opened successfully!");


            // 8.
            // Opening Encrypted Excel Files
            // Instantiate LoadOptions
            LoadOptions loadOptions6 = new LoadOptions();

            // Specify the password
            loadOptions6.Password = "******";

            // Create a Workbook object and opening the file from its path
            Workbook wbEncrypted = new Workbook(dataDir + "encryptedBook.xls", loadOptions6);
            Console.WriteLine("Encrypted excel file opened successfully!");


            // 9.
            // Opening File with Data only
            // Load only specific sheets with data and formulas
            // Other objects, items etc. would be discarded

            // Instantiate LoadOptions specified by the LoadFormat
            LoadOptions loadOptions7 = new LoadOptions(LoadFormat.Xlsx);

            // Set the LoadDataOption
            LoadDataOption dataOption = new LoadDataOption();
            // Specify the sheet(s) in the template file to be loaded
            dataOption.SheetNames = new string[] { "Sheet2" };
            dataOption.ImportFormula = true;
            // Only data and formatting should be loaded.
            loadOptions7.LoadDataAndFormatting = true;
            // Specify the LoadDataOption
            loadOptions7.LoadDataOptions = dataOption;

            // Create a Workbook object and opening the file from its path
            Workbook wb = new Workbook(dataDir + "Book1.xlsx", loadOptions7);
            Console.WriteLine("File data imported successfully!");
            // ExEnd:1
        }
示例#10
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");



            // 1.
            // Opening through Path
            //Creating a Workbook object and opening an Excel file using its file path
            Workbook workbook1 = new Workbook(dataDir + "Book1.xls");

            Console.WriteLine("Workbook opened using path successfully!");


            // 2.
            // Opening through Stream
            //Create a Stream object
            FileStream fstream = new FileStream(dataDir + "Book2.xls", FileMode.Open);

            //Creating a Workbook object, open the file from a Stream object
            //that contains the content of file and it should support seeking
            Workbook workbook2 = new Workbook(fstream);

            Console.WriteLine("Workbook opened using stream successfully!");
            fstream.Close();


            // 3.
            // Opening Microsoft Excel 97 - 2003 Files
            //Get the Excel file into stream
            FileStream stream = new FileStream(dataDir + "Book_Excel97_2003.xls", FileMode.Open);

            //Instantiate LoadOptions specified by the LoadFormat.
            LoadOptions loadOptions1 = new LoadOptions(LoadFormat.Excel97To2003);

            //Create a Workbook object and opening the file from the stream
            Workbook wbExcel97 = new Workbook(stream, loadOptions1);

            Console.WriteLine("Microsoft Excel 97 - 2003 workbook opened successfully!");


            // 4.
            // Opening Microsoft Excel 2007 Xlsx Files
            //Instantiate LoadOptions specified by the LoadFormat.
            LoadOptions loadOptions2 = new LoadOptions(LoadFormat.Xlsx);

            //Create a Workbook object and opening the file from its path
            Workbook wbExcel2007 = new Workbook(dataDir + "Book_Excel2007.xlsx", loadOptions2);

            Console.WriteLine("Microsoft Excel 2007 workbook opened successfully!");


            // 5.
            // Opening SpreadsheetML Files
            //Instantiate LoadOptions specified by the LoadFormat.
            LoadOptions loadOptions3 = new LoadOptions(LoadFormat.SpreadsheetML);

            //Create a Workbook object and opening the file from its path
            Workbook wbSpreadSheetML = new Workbook(dataDir + "Book3.xml", loadOptions3);

            Console.WriteLine("SpreadSheetML file opened successfully!");


            // 6.
            // Opening CSV Files
            //Instantiate LoadOptions specified by the LoadFormat.
            LoadOptions loadOptions4 = new LoadOptions(LoadFormat.CSV);

            //Create a Workbook object and opening the file from its path
            Workbook wbCSV = new Workbook(dataDir + "Book_CSV.csv", loadOptions4);

            Console.WriteLine("CSV file opened successfully!");


            // 7.
            // Opening Tab Delimited Files
            //Instantiate LoadOptions specified by the LoadFormat.
            LoadOptions loadOptions5 = new LoadOptions(LoadFormat.TabDelimited);

            //Create a Workbook object and opening the file from its path
            Workbook wbTabDelimited = new Workbook(dataDir + "Book1TabDelimited.txt", loadOptions5);

            Console.WriteLine("Tab delimited file opened successfully!");


            // 8.
            // Opening Encrypted Excel Files
            //Instantiate LoadOptions
            LoadOptions loadOptions6 = new LoadOptions();

            //Specify the password
            loadOptions6.Password = "******";

            //Create a Workbook object and opening the file from its path
            Workbook wbEncrypted = new Workbook(dataDir + "encryptedBook.xls", loadOptions6);

            Console.WriteLine("Encrypted excel file opened successfully!");


            // 9.
            // Opening File with Data only
            //Load only specific sheets with data and formulas
            //Other objects, items etc. would be discarded

            //Instantiate LoadOptions specified by the LoadFormat
            LoadOptions loadOptions7 = new LoadOptions(LoadFormat.Xlsx);

            //Set the LoadDataOption
            LoadDataOption dataOption = new LoadDataOption();

            //Specify the sheet(s) in the template file to be loaded
            dataOption.SheetNames    = new string[] { "Sheet2" };
            dataOption.ImportFormula = true;
            //Only data should be loaded.
            loadOptions7.LoadDataOnly = true;
            //Specify the LoadDataOption
            loadOptions7.LoadDataOptions = dataOption;

            //Create a Workbook object and opening the file from its path
            Workbook wb = new Workbook(dataDir + "Book1.xlsx", loadOptions7);

            Console.WriteLine("File data imported successfully!");
        }