Esempio n. 1
0
        private void Btn_ExportarDatosINMContacto_Click(object sender, RoutedEventArgs e) // eventodel boton Exportar Excel que me permite exportar a un archivo excel. los datos que tengo en el DataGrid
        {
            try
            {
                grid_InmueblesPropietarios.SelectAllCells();
                grid_InmueblesPropietarios.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
                ApplicationCommands.Copy.Execute(null, grid_InmueblesPropietarios);
                String resultat = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
                String result   = (string)Clipboard.GetData(DataFormats.Text);
                grid_InmueblesPropietarios.UnselectAllCells();
                SaveFileDialog salvar_archivo = new SaveFileDialog(); //creando ventana de guardado
                salvar_archivo.Filter = "archivo xml|*.xls";          //filtro para la extencion como se puede guardar el archivo
                salvar_archivo.Title  = "Guandar archivo excel";      //nombre de la ventana de guardado
                salvar_archivo.ShowDialog();                          //abre la ventana de guardado
                if (salvar_archivo.FileName != "")
                {
                    //System.IO.FileStream fileStream = (System.IO.FileStream)salvar_archivo.OpenFile();
                    System.IO.StreamWriter file1 = new System.IO.StreamWriter((System.IO.FileStream)salvar_archivo.OpenFile());
                    file1.WriteLine(result.Replace(',', ' '));
                    file1.Close();
                }

                MessageBox.Show("se exportaron los datos correctamente");
            }
            catch (Exception ex)
            {
                logger.Error("ERROR al exportar inmueblesfiltro-> {0}", ex.ToString());
                MessageBox.Show("error exportar");
            }
        }
Esempio n. 2
0
        private string GetClipboardContent()
        {
            if (WinClipboard.ContainsText())
            {
                return(WinClipboard.GetText());
            }

            // ReSharper disable once InvertIf
            if (WinClipboard.ContainsImage())
            {
                MemoryStream imageStream = (MemoryStream)WinClipboard.GetData(DataFormats.Dib);
                BitmapSource imageBitmap = DibToBitmapConverter.Read(imageStream);

                if (imageBitmap == null)
                {
                    Logger.Error("Unable to create bitmap from image copied into the clipboard!");
                    return(null);
                }

                using (MemoryStream rawImage = new MemoryStream()) {
                    BitmapEncoder encoder = new PngBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(imageBitmap));
                    encoder.Save(rawImage);
                    return($"{pngImageHeader}{Convert.ToBase64String(rawImage.ToArray())}");
                }
            }

            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Executes the CSV export process
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ExportButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // select all cells
                ResultGrid.SelectAllCells();
                // copy data to clipboard
                ResultGrid.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
                ApplicationCommands.Copy.Execute(null, ResultGrid);
                // clipboard contains data... unselect all cells
                ResultGrid.UnselectAllCells();
                // save data from clipboard to variable
                var result = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
                // data is in variable, clear clipboard
                Clipboard.Clear();

                // create a Save-File Dialog
                var sfd = new System.Windows.Forms.SaveFileDialog();
                sfd.Filter = @"CSV files (*.csv)|*.csv";
                // if dialog displayed successfully
                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    // write data to file using a StreamWriter
                    var writer = new StreamWriter(sfd.OpenFile());
                    writer.WriteLine(result);
                    writer.Close();
                    MessageBox.Show("CSV Export complete");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("CSV Export failed. \n" + ex.Message);
                Debug.WriteLine(ex);
            }
        }
        private void ExportButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ResultGrid.SelectAllCells();
                ResultGrid.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
                ApplicationCommands.Copy.Execute(null, ResultGrid);
                ResultGrid.UnselectAllCells();
                var result = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
                Clipboard.Clear();

                var sfd = new System.Windows.Forms.SaveFileDialog();
                sfd.Filter = @"CSV files (*.csv)|*.csv";
                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var writer = new StreamWriter(sfd.OpenFile());
                    writer.WriteLine(result);
                    writer.Close();
                }

                MessageBox.Show("CSV Export complete.");
            }
            catch (Exception ex)
            {
                MessageBox.Show("CSV Export failed. \n" + ex.Message);
            }
        }
        public static bool TryGetLinkedWClipboardId(out Guid guid)
        {
            var guidObj = SysClipboard.GetData(LinkedWClipboardIdFormat);

            guid = guidObj is Guid guidCasted ? guidCasted : Guid.Empty;
            return(guid != Guid.Empty);
        }
        private void SaveDataGridToExcel(string filename, DataGrid grid)
        {
            EnsureDirectoryExists(filename);

            grid.SelectAllCells();
            grid.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
            ApplicationCommands.Copy.Execute(null, grid);
            String resultat = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
            String result   = (string)Clipboard.GetData(DataFormats.Text);

            grid.UnselectAllCells();
            System.IO.StreamWriter file1 = new System.IO.StreamWriter(filename);
            file1.WriteLine(result.Replace(',', ' '));
            file1.Close();
        }
Esempio n. 7
0
        private string SaveReportInFile()
        {
            StringBuilder sb          = new StringBuilder();
            String        result      = "";
            var           replacedStr = "";

            if (FormRow.Items.Count > 0)
            {
                FormRow.SelectAllCells();
                FormRow.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
                ApplicationCommands.Copy.Execute(null, FormRow);
                CBlowingRow.UnselectAllCells();
                result = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
                // replacedStr = result.Replace(",", ";");
                sb.Append(result);
            }


            if (BlowingRow.Items.Count > 0)
            {
                BlowingRow.SelectAllCells();
                BlowingRow.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
                ApplicationCommands.Copy.Execute(null, BlowingRow);
                BlowingRow.UnselectAllCells();
                result      = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
                replacedStr = result.Replace(",", ";");
                sb.Append(replacedStr);
            }


            if (CBlowingRow.Items.Count > 0)
            {
                CBlowingRow.SelectAllCells();
                CBlowingRow.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
                ApplicationCommands.Copy.Execute(null, CBlowingRow);
                CBlowingRow.UnselectAllCells();
                result      = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
                replacedStr = result.Replace(",", ";");
                sb.Append(replacedStr);
            }


            return(sb.ToString());
        }
        public void ClipboardToLayer()
        {
            if (!ActiveWindowHelper.MainWindowActive || !IsActive)
            {
                return;
            }

            try
            {
                GeneralHelpers.ExecuteSta(() =>
                {
                    var data = (string)Clipboard.GetData("layer");
                    if (data == null)
                    {
                        return;
                    }

                    var layerModel = JsonConvert.DeserializeObject <LayerModel>(data);
                    if (layerModel == null)
                    {
                        return;
                    }

                    if (SelectedLayer != null)
                    {
                        SelectedLayer.InsertAfter(layerModel);
                    }
                    else
                    {
                        SelectedProfile.Layers.Add(layerModel);
                        SelectedProfile.FixOrder();
                    }
                    Execute.OnUIThread(() => UpdateLayerList(layerModel));
                });
            }
            catch (Exception)
            {
                // ignored
            }
        }
Esempio n. 9
0
        public DataPackageView GetContent()
        {
            var dataPackage = new DataPackage();

            if (Clipboard.ContainsImage())
            {
                dataPackage.SetDataProvider(StandardDataFormats.Bitmap, async ct =>
                {
                    var bitmap       = Clipboard.GetImage();
                    var bitmapStream = new MemoryStream();

                    var bitmapEncoder = new BmpBitmapEncoder();
                    bitmapEncoder.Frames.Add(BitmapFrame.Create(bitmap));
                    bitmapEncoder.Save(bitmapStream);

                    // Letting a MemoryStream run around does not cause problems.
                    // The GC will take care of it, just like a byte[].
                    return(RandomAccessStreamReference.CreateFromStream(bitmapStream.AsRandomAccessStream()));
                });
            }
            if (Clipboard.ContainsText())
            {
                // Copying significant amounts of text still makes Clipboard.GetText() slow, so
                // we'll still use the SetDataProvider
                dataPackage.SetDataProvider(StandardDataFormats.Text, async ct =>
                {
                    return(Clipboard.GetText());
                });
            }
            if (Clipboard.ContainsData(DataFormats.Html))
            {
                dataPackage.SetDataProvider(StandardDataFormats.Html, async ct =>
                {
                    return(Clipboard.GetData(DataFormats.Html));
                });
            }
            if (Clipboard.ContainsData(DataFormats.Rtf))
            {
                dataPackage.SetDataProvider(StandardDataFormats.Rtf, async ct =>
                {
                    return(Clipboard.GetData(DataFormats.Rtf));
                });
            }
            if (Clipboard.ContainsFileDropList())
            {
                dataPackage.SetDataProvider(StandardDataFormats.StorageItems, async ct =>
                {
                    var list            = Clipboard.GetFileDropList();
                    var storageItemList = new List <IStorageItem>(list.Count);
                    foreach (var path in list)
                    {
                        var attr = File.GetAttributes(path);
                        if (attr.HasFlag(global::System.IO.FileAttributes.Directory))
                        {
                            storageItemList.Add(await StorageFolder.GetFolderFromPathAsync(path));
                        }
                        else
                        {
                            storageItemList.Add(await StorageFile.GetFileFromPathAsync(path));
                        }
                    }
                    return(storageItemList);
                });
            }

            return(dataPackage.GetView());
        }