string filename;
saveFileDialog1.Filter = "xlsx files (*.xlsx)|*.xlsx";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
saveFileDialog1.ShowDialog();
filename = saveFileDialog1.FileName;
if (filename == "") filename = "";
else
{
gridView1.ExportToXlsx(filename);
System.Diagnostics.Process.Start(filename);
}
Category: EXCEL
VISUAL STUDIO 2013 VISUAL BASIC GRIDE EXCELDEN YAPIŞTIR
ONCE BU FONKSIYONU EKLE;
———————-
Sub pastefromclipboardtodatagridview(ByVal dgv As DataGridView)
Dim rowSplitter As Char() = {vbCr, vbLf}
Dim columnSplitter As Char() = {vbTab}
‘get the text from clipboard
Dim dataInClipboard As IDataObject = Clipboard.GetDataObject()
Dim stringInClipboard As String = CStr(dataInClipboard.GetData(DataFormats.Text))
‘split it into lines
Dim rowsInClipboard As String() = stringInClipboard.Split(rowSplitter, StringSplitOptions.RemoveEmptyEntries)
‘get the row and column of selected cell in grid
Dim r As Integer = dgv.SelectedCells(0).RowIndex
Dim c As Integer = dgv.SelectedCells(0).ColumnIndex
‘add rows into grid to fit clipboard lines
If (dgv.Rows.Count < (r + rowsInClipboard.Length)) Then
dgv.Rows.Add(r + rowsInClipboard.Length – dgv.Rows.Count)
End If
‘ loop through the lines, split them into cells and place the values in the corresponding cell.
Dim iRow As Integer = 0
While iRow < rowsInClipboard.Length
‘split row into cell values
Dim valuesInRow As String() = rowsInClipboard(iRow).Split(columnSplitter)
‘cycle through cell values
Dim iCol As Integer = 0
While iCol < valuesInRow.Length
‘assign cell value, only if it within columns of the grid
If (dgv.ColumnCount – 1 >= c + iCol) Then
dgv.Rows(r + iRow).Cells(c + iCol).Value = valuesInRow(iCol)
End If
iCol += 1
End While
iRow += 1
End While
End Sub
—————
1 ADET DATAGRIDVIEW YARAT
1 ADET BUTTON YARAT
CİFT TIKLA BUTTONA
KOD:
DataGridView1.AllowUserToAddRows = False
DataGridView1.Rows.Add()
pastefromclipboardtodatagridview(DataGridView1)
DataGridView1.AllowUserToAddRows = False
DataGridView1.Rows.Add()
pastefromclipboardtodatagridview(DataGridView1)
vs 2013 c# Devexpress gridview sağ tıklayarak excel dosyası olarak kaydet
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.OleDb;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
contextMenuStrip1 tıkla Excele kaydet item yarat ve çift tıkla ve yaz;
//excele kaydet
string filename;
saveFileDialog1.Filter = “xlsx files (*.xlsx)|*.xlsx”;
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
saveFileDialog1.ShowDialog();
filename = saveFileDialog1.FileName;
if (filename == “”) filename = “”; else gridView1.ExportToXlsx(filename);
Daha sonra gridcontrola tıkla ve contextmenustripini contextMenuStrip1 olarak seç
excel filter by combobox
excel live sheet 3 . gif olarak kaydeder
Not dosya c
ilk önce excelde
developer -> insert -> Button
buttonun ismini kaydet ve recorda bas ve ok bas ve a1e tıkla stop recording bas ve f11e bas aşağısı gibi yap. ( developer mode yoksa excel toolbara sağ tıklas-> customise the ribbona bas developeri seç ve sağa koy…)
Sub kaydet ()
Dim rng As Excel . Range
Set rng = Range (“A1:D38”)
If ExportRangeToPicture(rng, ” C range . gif “) Then
Else
End If
ActiveWorkbook.RefreshAll
Application.OnTime Now + TimeValue(“00:0: 10 “), ” kaydet ” ‘ 10 saniyede bir kaydeder
End Sub
ve daha sonra microsof excel objectse tıkla ve insert module bas ve içine aşağıdakileri yapıştır
Function ExportRangeToPicture(rng As Excel . Range , img As String) As Boolean
‘ save a range from Excel as a picture
‘ rng = Range to export
‘ img = filename & path
‘ basic error checking
‘ check for valid filetypes
‘ from http://peltiertech.com/WordPress/export-chart-as-image-file/
Const FILE_EXT As String = ” gif ,png,jpg,jpe,jpeg”
If InStr(FILE_EXT, LCase$(Right$(img, 3))) = 0 Then
GoTo ExitProc
End If
‘ check for valid path
Dim path As String
path = Left$(img, InStrRev(img, “\”))
If Dir(path, vbDirectory) = “” Then GoTo ExitProc
‘ check for valid range
Dim rRng As Excel . Range
On Error Resume Next
Set rRng = rng.CurrentRegion
On Error GoTo 0
If rRng Is Nothing Then GoTo ExitProc
‘ check for protected worksheet
If ActiveSheet.ProtectContents Then GoTo ExitProc
‘ copy range to picture, put into chart, export it
Application.ScreenUpdating = False
rRng.CopyPicture xlScreen, xlPicture
Dim cht As Excel .ChartObject
Set cht = ActiveSheet.ChartObjects.Add(0, 0, rng.Width + 10 , rng.Height + 10 )
With cht
.Chart.Paste
.Chart.Export img
.Delete
End With
‘ if we got this far, assume success
ExportRangeToPicture = True
ExitProc:
Application.ScreenUpdating = True
Set cht = Nothing
Set rRng = Nothing
End Function
Sub SaveMyBook()
‘Turn off Excel message alerts
Application.DisplayAlerts = False
‘Save this workbook.
ThisWorkbook.Save
‘Turn back on alerts
Application.DisplayAlerts = True
‘call this procedure again in another 15 mins
Application.OnTime Now + TimeValue(“00:00: 10 “), “SaveMyBook” ‘ 10 saniyede bir kaydeder
End Sub
——————————————–
body
{
margin: 0;
overflow: hidden;
}
#iframe1
{
height: 100%;
left: 0px;
position: absolute;
top: 0px;
width: 100%;
}
.image{
float:left;
margin-top:250px;
padding:12px;
width:200px;
}
——————————————-
Not enson birtane daha button koy arasına end koy tüm kodları durdurur…
Excel Live sheet gif
sayfaya bir button yarat kaydet koy ismini
module 1
———————–
Sub kaydet()
Dim rng As Excel.Range
Set rng = Range(“A1:J19”)
If ExportRangeToPicture(rng, “C:\MSDS500\1\RAPORGUNLUKAYLIKTV\tv2.gif”) Then
Else
End If
If ExportRangeToPicture(rng, “\\DIGIKEY-PC\htmltvwebvesms\tv2.gif”) Then
Else
End If
ActiveWorkbook.RefreshAll
Application.OnTime Now + TimeValue(“00:00:30”), “kaydet” ’10 saniyede bir kaydeder
End Sub
Sub durdur()
End
End Sub
———————–
module2
Function ExportRangeToPicture(rng As Excel.Range, img As String) As Boolean
‘ save a range from Excel as a picture
‘ rng = Range to export
‘ img = filename & path
‘ basic error checking
‘ check for valid filetypes
‘ from http://peltiertech.com/WordPress/export-chart-as-image-file/
Const FILE_EXT As String = “gif,png,jpg,jpe,jpeg”
If InStr(FILE_EXT, LCase$(Right$(img, 3))) = 0 Then
GoTo ExitProc
End If
‘ check for valid path
Dim path As String
path = Left$(img, InStrRev(img, “\”))
If Dir(path, vbDirectory) = “” Then GoTo ExitProc
‘ check for valid range
Dim rRng As Excel.Range
On Error Resume Next
Set rRng = rng.CurrentRegion
On Error GoTo 0
If rRng Is Nothing Then GoTo ExitProc
‘ check for protected worksheet
If ActiveSheet.ProtectContents Then GoTo ExitProc
‘ copy range to picture, put into chart, export it
Application.ScreenUpdating = False
On Error Resume Next
rRng.CopyPicture xlScreen, xlPicture
On Error GoTo 0
Dim cht As Excel.ChartObject
Set cht = ActiveSheet.ChartObjects.Add(0, 0, rng.Width + 10, rng.Height + 10)
With cht
.Chart.Paste
.Chart.Export img
.Delete
End With
‘ if we got this far, assume success
ExportRangeToPicture = True
ExitProc:
Application.ScreenUpdating = True
Set cht = Nothing
Set rRng = Nothing
End Function
Sub SaveMyBook()
‘Turn off Excel message alerts
Application.DisplayAlerts = False
‘Save this workbook.
ThisWorkbook.Save
‘Turn back on alerts
Application.DisplayAlerts = True
‘call this procedure again in another 15 mins
Application.OnTime Now + TimeValue(“00:00:30”), “SaveMyBook” ’10 saniyede bir kaydeder
End Sub
——————————-
html yarat
body
{
margin: 0;
overflow: hidden;
}
#iframe1
{
height: 100%;
left: 0px;
position: absolute;
top: 0px;
width: 100%;
}
.image{
float:left;
margin-top:250px;
padding:12px;
width:200px;
}
excel dbf “the query did not run or the database table could not be opened”
excel dbf açmaya çalışırken bazı dosyalarda hata verirse “the query did not run or the database table could not be opened”
excelde önce
data- from other sources – from data connection – micorosft jet4- klasörü yaz -all git extended properties dBASE IV yaz
o dbfyi seç hatayı verdikten sonra tekrar
data – from other sources-from data connection-odbc dsn- dbf file-next-connect specicif tikini kaldır-next bas-browsea bas ve C:\Users\usernama\Documents\My Data Sources deki o dbfyi seç.
EXCEL 2013 CONNECT DBF FILE and QUERY BY TODAY
EXCELDE DATA->FROM OTHER SOURCES->OTHER ADVANCED->MICROSOFT JET 4 ÇİFT TIKLA-> ALL TABINA GEÇ->DATASOURCEU DBF DOSYASININ BULUNDUGU KLASORU EKLE->EXTENDED PROPERTIES=dBASE IV YAP-> OKE BAS->DBF DOSYASI CIKACAK LISTEDE CIFT TIKLA->FINISHE BAS->PROPERTIESA BAS DEFINITIONA TIKLA->COMMAND TYPE=SQL->SELECT * FROM DOSYAADI.DBF
select * from DATA
WHERE TARIH>=date()
Delphide surukle birak excel dosyasini ve cxgride al sheetleri kodlari
unit Unit1;
interface
(*
Code for the article:
Accessing and managing MS Excel sheets with Delphi
http://delphi.about.com/library/weekly/aa090903a.htm
How to retrieve, display and edit Microsoft Excel spreadsheets
with ADO (dbGO) and Delphi. This step-by-step article describes
how to connect to Excel, retrieve sheet data, and enable editing
of data (using the DBGrid). You'll also find a list of most common
errors (and how to deal with them) that might pop up in the process.
*)
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, DBCtrls, Grids, DBGrids, DB, ADODB, Buttons,
ComCtrls, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
cxEdit, cxDBData, cxGridLevel, cxClasses, cxControls, cxGridCustomView,
cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid, cxPC;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
cxPageControl1: TcxPageControl;
cxTabSheet1: TcxTabSheet;
cxTabSheet2: TcxTabSheet;
cxGrid1: TcxGrid;
cxGrid1DBTableView1: TcxGridDBTableView;
cxGrid1Level1: TcxGridLevel;
DBNavigator1: TDBNavigator;
Edit3: TEdit;
ListBox1: TListBox;
ADOConnection1: TADOConnection;
ADOConnection2: TADOConnection;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
l1: TLabel;
l2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
BitBtn1: TBitBtn;
ComboBox1: TComboBox;
Edit4: TEdit;
Panel2: TPanel;
Button1: TButton;
Button2: TButton;
StatusBar1: TStatusBar;
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
procedure ConnectToExcel;
procedure FetchData;
procedure GetFieldInfo;
procedure DisplayException(Sender:TObject; E: Exception);
public
procedure WMDROPFILES(var msg : TWMDropFiles) ;
message WM_DROPFILES;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses typinfo,shellapi;
{ TForm1 }
procedure TForm1.ConnectToExcel;
var strConn : widestring;
i:integer;
begin
i := Pos('xlsx',edit1.Text);
if i>1 then strConn:='Provider=Microsoft.ACE.OLEDB.12.0;' +
'Data Source=' + Edit1.Text + ';' +
'Extended Properties="Excel 12.0;HDR=YES";'
else
//xlsx
//Provider=Microsoft.ACE.OLEDB.12.0;
//Data Source=c:\myFolder\myExcel2007file.xlsx;
//Extended Properties="Excel 12.0;HDR=YES";
strConn:='Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=' + Edit1.Text + ';' +
'Extended Properties=Excel 8.0;';
AdoConnection1.Connected:=False;
AdoConnection1.ConnectionString:=strConn;
try
AdoConnection1.Open;
AdoConnection1.GetTableNames(ComboBox1.Items,True);
except
ShowMessage('Unable to connect to Excel, make sure the workbook ' + Edit1.Text + ' exist!');
raise;
end;
end;(*ConnectToExcel*)
procedure TForm1.FetchData;
begin
StatusBar1.SimpleText:='';
if not AdoConnection1.Connected then ConnectToExcel;
AdoQuery1.Close;
if combobox1.Text ='' then combobox1.ItemIndex:=0;
ShowMessage(Edit2.Text+l1.Caption+ComboBox1.Text+l2.Caption);
AdoQuery1.SQL.Text:=Edit2.Text+l1.Caption+ComboBox1.Text+l2.Caption;
try
AdoQuery1.Open;
except
ShowMessage('Unable to read data from Excel, make sure the query ' + Edit1.Text + ' is meaningful!');
raise;
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
FetchData;
GetFieldInfo;
cxGrid1DBTableView1.BeginUpdate;
cxGrid1DBTableView1.ClearItems;
cxGrid1DBTableView1.DataController.CreateAllItems;
cxGrid1DBTableView1.EndUpdate;
cxGrid1DBTableView1.Columns[0].Summary.FooterKind:=skCount;
cxGrid1DBTableView1.ApplyBestFit();
//grdCevapDBTableView2.BeginUpdate;
//grdCevapDBTableView2.ClearItems;
//fillGridView(grdCevapDBTableView2,command);
//grdCevapDBTableView2.DataController.CreateAllItems;
//grdCevapDBTableView2.EndUpdate;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles( Handle, True ) ;
AdoConnection1.LoginPrompt:=False;
AdoQuery1.Connection:=AdoConnection1;
DataSource1.DataSet:=AdoQuery1;
DBNavigator1.DataSource:=DataSource1;
Application.OnException:= DisplayException;
end;
procedure TForm1.DisplayException(Sender: TObject; E: Exception);
begin
StatusBar1.SimpleText:=E.Message;
edit3.Text:=E.Message;
end;
procedure TForm1.GetFieldInfo;
var
i : integer;
ft : TFieldType;
sft : string;
fname : string;
begin
ListBox1.Clear;
for i := 0 to AdoQuery1.Fields.Count - 1 do
begin
ft := AdoQuery1.Fields[i].DataType;
sft := GetEnumName(TypeInfo(TFieldType), Integer(ft));
fname:= AdoQuery1.Fields[i].FieldName;
ListBox1.Items.Add(Format('%d) NAME: %s TYPE: %s',[1+i, fname, sft]));
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var sAppend : string;
begin
sAppend:='INSERT INTO [Sheet2$] IN "' + Edit1.Text + '" "Excel 8.0;" SELECT AuthorEmail, Title, Description FROM Articles';
AdoQuery2.SQL.Text:=sAppend;
AdoQuery2.ExecSQL;
end;
procedure TForm1.Button1Click(Sender: TObject);
var sCopy : string;
begin
sCopy := 'SELECT * INTO ["Excel 8.0;Database=' + Edit1.Text + '"].[SheetAuthors] FROM Authors';
AdoQuery2.SQL.Text:=sCopy;
AdoQuery2.ExecSQL;
end;
procedure TForm1.WMDROPFILES(var msg: TWMDropFiles) ;
const
MAXFILENAME = 255;
var
cnt, fileCount : integer;
fileName : array [0..MAXFILENAME] of char;
begin
// how many files dropped?
fileCount := DragQueryFile(msg.Drop, $FFFFFFFF, fileName, MAXFILENAME) ;
// query for file names
for cnt := 0 to -1 + fileCount do
begin
DragQueryFile(msg.Drop, cnt, fileName, MAXFILENAME) ;
//do something with the file(s)
Edit1.Text:=fileName;
end;
//release memory
DragFinish(msg.Drop) ;
end;
end.


