W

로컬 텍스트 엑셀 파일 읽기/쓰기

· 16년 전 · 5342

익스플로우의 보안에 허용만 가능하면 자바스크립트 상에서도 읽기/쓰기가 가능하다.

 

우선 text파일 읽고 쓰는 예제이다.(C:\\book1.txt를 읽고 씀)

 

=====================================================================================================================

<html>
<head>
<title>file save/load</title>

 

<script type="text/javascript">

    var fso=new ActiveXObject("Scripting.FileSystemObject");
    var filename="C:\\book1.txt";
    function savefile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,2,true);
        f.Write(myarea.innerHTML);
        f.Close();
    }
   
    function loadfile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,1);
        r=f.ReadAll();
        f.Close();
        myarea.innerHTML=r;
    }
   
   
    //function window.onload() {
    //    loadfile(filename);
    //}
</script>


</head>
<body>
 <table>
  <tr>
   <td>
    <div id=myarea contenteditable=true style="width:320;height:240;border:solid 2 inset;overflow:scroll;background-color:silver;"></div>
    <br><input type=button value=load onclick=loadfile()><input type=button value=save onclick=savefile()>
   </td>
  </tr>
 </table>
</form>
</body>
</html>

 

======================================Excel 파일 열고 쓰기 =================================================

- 쓰기 -

<script type="text/javascript">

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\book1.xls");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();
</script>

 

- 열기 -

function StartExcel() {
var oExcel;

var oWBook;
oExcel = new ActiveXObject("Excel.Application");

oExcel.Visible = true;

oExcel.workbooks.open("C:/test.xls");

oExcel.Quit();

oExcel = null;
}

 

간단한 파일 읽기의 경우 상당히 유용할 수 있겠다..

 
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
15년 전 조회 1,789
15년 전 조회 605
15년 전 조회 1,096
15년 전 조회 1,062
15년 전 조회 2,858
15년 전 조회 3,173
15년 전 조회 1,848
15년 전 조회 1,355
15년 전 조회 1,973
15년 전 조회 1,478
15년 전 조회 1,080
15년 전 조회 3,777
15년 전 조회 1,420
15년 전 조회 1,516
15년 전 조회 2,743
15년 전 조회 1,440
15년 전 조회 4,168
15년 전 조회 2,380
15년 전 조회 3,157
15년 전 조회 1,774
15년 전 조회 2,002
15년 전 조회 1,305
15년 전 조회 4,381
15년 전 조회 3,958
15년 전 조회 3,783
15년 전 조회 5,200
15년 전 조회 3,421
15년 전 조회 1,801
15년 전 조회 1,760
15년 전 조회 1,905
15년 전 조회 1,598
15년 전 조회 3,998
15년 전 조회 2,911
15년 전 조회 2,093
15년 전 조회 1,673
15년 전 조회 1,908
15년 전 조회 2,390
15년 전 조회 1,472
15년 전 조회 2,407
15년 전 조회 1,739
15년 전 조회 1,839
15년 전 조회 1,493
15년 전 조회 2,177
15년 전 조회 1,510
15년 전 조회 1,925
16년 전 조회 2,116
16년 전 조회 1,188
16년 전 조회 1,256
16년 전 조회 1,902
16년 전 조회 5,343
16년 전 조회 1,641
16년 전 조회 2,154
16년 전 조회 2,351
16년 전 조회 1,505
16년 전 조회 1,310
16년 전 조회 2,227
16년 전 조회 4,940
16년 전 조회 2,214
16년 전 조회 2,870
16년 전 조회 1,754
16년 전 조회 3,607
16년 전 조회 4,444
16년 전 조회 3,109
16년 전 조회 2,355
16년 전 조회 2,441
16년 전 조회 2,687
16년 전 조회 2,174
16년 전 조회 5,516
16년 전 조회 3,372
16년 전 조회 1,363
16년 전 조회 1,706
16년 전 조회 5,078
16년 전 조회 2,313
16년 전 조회 3,417
16년 전 조회 2,654
16년 전 조회 1,570
16년 전 조회 5,361
16년 전 조회 2,479
16년 전 조회 5,971
16년 전 조회 1,948
16년 전 조회 4,019
16년 전 조회 3,037
16년 전 조회 2,224
16년 전 조회 2,241
16년 전 조회 4,407
16년 전 조회 3,302
16년 전 조회 2,839
16년 전 조회 2,975
16년 전 조회 2,093
16년 전 조회 1,774
16년 전 조회 1,686
16년 전 조회 1,409
16년 전 조회 1,682
16년 전 조회 1,911
16년 전 조회 1,605
16년 전 조회 4,848
16년 전 조회 3,832
16년 전 조회 1,801
16년 전 조회 1,545
16년 전 조회 2,281
🐛 버그신고